views:

65

answers:

2

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?

+6  A: 

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>

link to msdn for more detail

Kevin
+2  A: 

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>
JayJay
+1 this solution is much simpler and cleaner.
Maslow