How to validate a dropbox

Aug 29, 2014 at 8:48 PM
Hi ,
How to validate a drop box using DAvalidation

Arun A
Sep 1, 2014 at 8:53 PM
Edited Sep 1, 2014 at 8:54 PM
I'm not sure what is your issue. In case you want to validate that user selected something make a default value an empty string and then property marked with RequiredAttribute should work just fine. Otherwise you'll need to write your own validation attribute and a JavaScript function as shown in the last part of the article about the internals of the validator:

Model class:
public string Foo { get; set; }
<asp:DropDownList runat="server" ID="ddlFoo">
    <asp:ListItem Text="Select" Value=""></asp:ListItem>
    <asp:ListItem Text="Quux" Value="1"></asp:ListItem>
    <asp:ListItem Text="Bat" Value="2"></asp:ListItem>
    <asp:ListItem Text="Baz" Value="3"></asp:ListItem>
<dav:DataAnnotationsValidator runat="server" ID="davFoo"
    ObjectProperty="Foo" />