Validate Listbox using Require filed validator control in asp.net | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Validate Listbox using Require filed validator control in asp.net

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

Validate Listbox
Click here to Enlarge

Description: 

Example:
Add a webform to project. Drag and drop the Listbox control from toolbox to webform.
<center>
    <fieldset style="width:30%;height:100px">
    <legend>Validate Listbox using Requirefield validator control</legend>
       Please Select Country : <asp:ListBox runat="server" ID="lstboxcountry" Width="35%">
        <asp:ListItem Value="0">--Select Country--</asp:ListItem>
       <asp:ListItem Value="1">India</asp:ListItem>
 <asp:ListItem Value="2">China</asp:ListItem>
 <asp:ListItem Value="3">Russia</asp:ListItem>
 <asp:ListItem Value="4">Cuba</asp:ListItem>
 <asp:ListItem Value="5">Iran</asp:ListItem>
 <asp:ListItem Value="6">Brazil</asp:ListItem>
 <asp:ListItem Value="7">Sri lanka</asp:ListItem>
       </asp:ListBox>
       </br>                
                <asp:RequiredFieldValidator ID="rfvlstboxcountry"
            ControlToValidate="lstboxcountry" InitialValue="0" runat="server"
            ErrorMessage="Please select Country" ForeColor="#FF3300"></asp:RequiredFieldValidator>
        </fieldset>
        </center>

Note: If not want “—Select Country—“ option then set the InitialValue="".
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

Hi theгe, thiѕ weekend is pleаsant in favor of me, as this
time i am reading tthіs fantastic iformative paragraph here aat my
home.

my blog - equities trader salary

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

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