Introduction:
Here I will explain how to Dropdownlist validation in Asp.net Using Required field validator.
In previous articles I explained validate email address using code for validating checkbox in asp.net In ASP.Net And Many Article Relating to Validation Now I Will Explained Dropdownlist validation in Asp.net Using RequiredField validator In Asp.net.
To implement this one we need to write code as shown below in your aspx page
<asp:DropDownList CssClass="dropdown" ValidationGroup="g1"
ID="dropdown" runat="server" OnSelectedIndexChanged="dropdown_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="dropdown" ID="RequiredFieldValidator1"
ValidationGroup="g1" CssClass="dropdown" ErrorMessage="Select Dropdown"InitialValue="--Select Asprockers--" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>
dropdown.Items.Insert(0, "--Select Asprockers--"
));