DropDownList Must Have a Value Selected Other Than the Default : Required Field « Validation by Control « ASP.Net






DropDownList Must Have a Value Selected Other Than the Default


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" ValidationGroup="DDL">
            <asp:ListItem>--Please Select--</asp:ListItem>
            <asp:ListItem>Red</asp:ListItem>
            <asp:ListItem>Green</asp:ListItem>
            <asp:ListItem>Blue</asp:ListItem>
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 
                                    runat="server" 
                                    ControlToValidate="DropDownList1"
                                    ErrorMessage="DropDownList1 Must Have a Value Selected" 
                                    InitialValue="--Please Select--"
                                    SetFocusOnError="True" 
                                    ValidationGroup="DDL">*</asp:RequiredFieldValidator><br />

    </div>
    </form>
</body>
</html>

 








Related examples in the same category

1.Must enter: Required Field Validator (C#)
2.Checking Against an Initial Value with a RequiredFieldValidator Control (VB.net)
3.Required field validator (VB.net)
4.RequiredFieldValidator Demo: You must enter your name (VB.net)
5.Validation for aspText: cannot be empty, integer range (MaximumValue,MinimumValue) (VB.net)