Introduction: In
this article today I will explain how we can validate Dropdownlist using Require
filed validator control in asp.net
Description:
In the previous article I have explained Show Gridview row detail in Tooltip on mousehover using Jquery in asp.net;Fill dropdownlist with days, month and year in asp.net,Server side validation in MVC Razor using data annotation,Like linq query example and bind gridview,Create a dynamic Slider in asp.net, URL routing in asp.net website and Display message and header when Gridview is empty in asp.net.
We can validate the Dropdownlist
using Requirefield validator via set the InitialValue property
of Requirefield validator control.
Add a webform to project. Drag and drop the Dropdownlist
control from toolbox to webform.
<center>
<fieldset style="width:30%;height:150px">
<legend>Validate Dropdownlist using Requirefield
validator control</legend>
Please
Select Country : <asp:DropDownList ID="ddlcountry"
runat="server"
Width="20%">
<asp:ListItem Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="1">India</asp:ListItem>
<asp:ListItem Value="2">China</asp:ListItem>
<asp:ListItem Value="3">USA</asp:ListItem>
<asp:ListItem Value="4">Russia</asp:ListItem>
<asp:ListItem Value="5">Cuba</asp:ListItem>
<asp:ListItem Value="6">Iran</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="rfvcountry"
ControlToValidate="ddlcountry"
InitialValue="0"
runat="server"
ErrorMessage="Please
select Country"></asp:RequiredFieldValidator>
</fieldset>
</center>
Build and run the project.
No comments:
Post a Comment