Validate Dropdownlist using Require filed validator control in asp.net OR can we validate Dropdownlist by Requirefield validator | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Validate Dropdownlist using Require filed validator control in asp.net OR can we validate Dropdownlist by Requirefield validator

Introduction: In this article today I will explain how we can validate Dropdownlist using Require filed validator control in asp.net
Validate Dropdownlist using Require filed validator control

Description:
We can validate the Dropdownlist using Requirefield validator via set the InitialValue property of Requirefield validator control.

Example:
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.

Is this article helpful for you?

If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email. 

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget