Today I want to share a very simple stuff That I learned while working, its kind of a silly learning, but hopefully will help someone someday. I want to make sure that a DropDownList is been selected before submitting a form. In asp.net we have a control for validation name “RequiredFieldValidator”, till now I have seen using this with only textbox. Below an example is given.
But we can actually use this required field validator with DropDownList as well. Below another example is given for using with DropDownList
Note that in ListItem we have assigned Value=0 and in RequiredFieldValidator InitialValue=0 that is the main trick. If you have binding code in c# please make sure you also Set DataValueField.
Until next time.