for Example:- the following code will help you
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="Style1">
<asp:ListItem Value="0">select item</asp:ListItem>
<asp:ListItem Value="4">A</asp:ListItem>
<asp:ListItem Value="1">B</asp:ListItem>
<asp:ListItem Value="2">C</asp:ListItem>
<asp:ListItem Value="3">D</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator_Drop" runat="server" <asp:ListItem Value="0">select item</asp:ListItem>
<asp:ListItem Value="4">A</asp:ListItem>
<asp:ListItem Value="1">B</asp:ListItem>
<asp:ListItem Value="2">C</asp:ListItem>
<asp:ListItem Value="3">D</asp:ListItem>
</asp:DropDownList>
ErrorMessage="Select Any Items" ControlToValidate="DropDownList1"
CssClass="Style1" InitialValue="0"></asp:RequiredFieldValidator>
The main think is that you have to set Initial value Property with same as value of top of list Item of Dropdownlist
No comments:
Post a Comment