Nov 2 2006

DropDownList and RequiredFieldValidator

Category:Bil@l @ 12:57

Here is a small example to show you how to validate a DropDownList using RequiredFieldValidator:

<form id="Form1" method="post" runat="server">
   <asp:DropDownList id="DropDownList1" runat="server">
       <asp:ListItem Value="-1">--> Choose  <--<asp:ListItem>
       <asp:ListItem Value="1">Lebanon</asp:ListItem>
       <asp:ListItem Value="2">Kuwait</asp:ListItem>
   </asp:DropDownList>
   <asp:RequiredFieldValidator id="RequiredFieldValidator1"
       runat="server" ErrorMessage="You must select a valid option"
       ControlToValidate="DropDownList1" InitialValue="-1"
       Display="Dynamic" />
<P>
    <asp:Button id="Button1" runat="server" Text="Post Back" />
<P>
<form>

Hope this helps,

Regards

Tags:

Comments are closed