How to validate a DropDownList box in ASP.NET?

Posted by Raja under ASP.NET category on | Views : 10934
You can use RequiredFieldValidator control with InitialValue as the default value for the DropDownList box.

<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Selected="True">Select a name</asp:ListItem>

<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server" ErrorMessage="Please make a selection"
InitialValue="Select a name" >

In this case, unless the user will select other item than "Select a name" from the dropdown, the form will not be submitted.

Comments or Responses

Login to post response