How to add initial option and ignore this option in the Required Validator in ASP.NET?
To add initial option and ignore this option in the Required Validator in ASP.NET, you have to do the following:
1- On pageLoad
function add the below:
ddlCity.Items.Insert(0, new ListItem("--- select one ---", "-1"));
2- In front code in specific in RequiredFieldValidator
Add InitialValue="-1"
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" CssClass="requiredMsg"
ValidationGroup="AddRequest" ControlToValidate="ddlCity" InitialValue="-1"
Text="Required Field" Display="Dynamic"></asp:RequiredFieldValidator>
Now, the --- select one ---
option is the initial value in dropdown list.