<asp:DropDownList runat="server" ID="ddl">
<asp:ListItem Text="-Select-" Value=""></asp:ListItem>
<asp:ListItem Text="One" Value="1"></asp:ListItem>
<asp:ListItem Text="Two" Value="2"></asp:ListItem>
<asp:ListItem Text="Three" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:CompareValidator ID="cvddl" runat="server" Text="Error"
ControlToValidate="ddl" Operator="NotEqual" ValueToCompare = ""
ValidationGroup="CreateRolls"></asp:CompareValidator>
I do want to validate dropdown, if select is selected error should be thrown. Main aim is that the value should be empty.
Is there is any methord to validate like this . Please help me with this
DropDownList
<asp:DropDownList ID="ddl" runat="server"
ValidationGroup="CreateRolls"
AppendDataBoundItems="true">
<asp:ListItem Text="-Select-" Value=""></asp:ListItem>
<asp:ListItem Text="One" Value="1"></asp:ListItem>
<asp:ListItem Text="Two" Value="2"></asp:ListItem>
<asp:ListItem Text="Three" Value="3"></asp:ListItem>
</asp:DropDownList>
RequiredFieldValidator
<asp:RequiredFieldValidator ID="rfvDDL" runat="server"
ControlToValidate="ddl"
Display="Dynamic"
ErrorMessage="Values is required."
InitialValue="-Select-"
ForeColor="Red"
ValidationGroup="CreateRolls" >
</asp:RequiredFieldValidator>
The Important property to be noted in the code is the following
ControlToValidate="ddl"
InitialValue="-Select-"
ValidationGroup="CreateRolls"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With