asp.net dropdownlist validation using Required Field Validation


First see the Dropdownlist

<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True">
                <asp:ListItem>--Select--</asp:ListItem>
                <asp:ListItem>Pen</asp:ListItem>
                <asp:ListItem>Pencil</asp:ListItem>
                <asp:ListItem>Rubber</asp:ListItem>
            </asp:DropDownList>
Then for validate see the requiredfield validator

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"
                ErrorMessage="Value Required!" InitialValue="--Select--"></asp:RequiredFieldValidator>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </div>

We need to set InitialValue property of the RequiredFieldValidator with the InitialValue of the DropDownList to make it work
Ebook Download
View all
Learn
View all