In this asp.net post we will learn how to validate dropdownlist control using requiredfield validator control in asp.net.
For understand validate dropdownllist control in asp.net using required field control create a asp.net web for with one dropdownlist control, button control along with requiredfield control.
take dropdownlist control and add some items in dropdownlist, In dropdownlist control we must select item from second to last, means requiredfiled validator control show the error message, if we select the first item from dropdownlist.
Here is the design code for dropdownlist example:
<asp:DropDownList ID="DropDownList1" runat="server" Width="180px"> <asp:ListItem>SELECT</asp:ListItem> <asp:ListItem>ABC</asp:ListItem> <asp:ListItem>PQR</asp:ListItem> <asp:ListItem>XYZ</asp:ListItem> </asp:DropDownList>
– design code for requiredfiled validator control:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1" ErrorMessage="Select Proper Option First !!" InitialValue="SELECT"></asp:RequiredFieldValidator>
here, we set two property of requiredfield validator
– ControlToValidator=”DropDownList1″
-InitialValue=”SELECT” <– Fist value of dropdownlist control
Here, is the output of dropdownlist control validate asp.net example:


