In my .aspx page, I have a dropdown list.
The first value that it defaults to is 'please choose', and it has the value of -1.
How can I add validation to it so someone chooses an item?
In my .aspx page, I have a dropdown list.
The first value that it defaults to is 'please choose', and it has the value of -1.
How can I add validation to it so someone chooses an item?
Add a required field Validator. There is a default value option which you can set to the default value of the drop down.
<asp:RequiredFieldValidator InitialValue="-1" ControlToValidate="yourControl" runat="server" ID="rf1"></asp:RequiredFieldValidator>
Change the value of 'please choose' to Value="" and try this:
<asp:RequiredFieldValidator ID="req" runat="server" ControlToValidate="YourDropDownList"
ErrorMessage="Select item" Display="Dynamic"></asp:RequiredFieldValidator>