Validating Dropdown List using RequiredFieldValidator

Neeks
Posted by Neeks under ASP.NET category on | Views : 17545
<form id="form1" runat="server">
<div>
Validating Dropdown List using RequiredFieldValidator
<hr />
<%--Creating the DropDownList control--%>
<asp:DropDownList runat="server" ID="ddl">
<%--Adding the Items in DropDownList--%>
<asp:ListItem Value="-1">Select City</asp:ListItem>
<asp:ListItem Value="1">Ahmedabad</asp:ListItem>
<asp:ListItem Value="2">Baroda</asp:ListItem>
</asp:DropDownList>
<%--Creating RequiredFieldValidator Control--%>
<asp:RequiredFieldValidator runat="server" ID="rfv" ControlToValidate="ddl" InitialValue="-1" ErrorMessage="Select City">*</asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>

Comments or Responses

Login to post response