DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

How to set required field validator for dropdownlist

My colleague Sweta asked me to how to set required field validator for doopdownlist.
so to set required field validator for doopdownlist we need to follow these steps.

1. let your dropdown list in such format that first item of it is "--Select--" as in example give below.

2. if your valumember is integer type then set value '0' of valuemamber
for "--Select--"

3. take required field validator and select your dropdownlist as control to validate and in field "Initial Value" enter '0' (without single quotes)

Note: if you are using GUID (uniqueidentifier) or any other type of value as valuemember of dropdownlist then place value of "-- select--" in "Initial Value" field of required field validator.

example:
< asp:DropDownList ID="DropDownList1" runat="server" Height="37px" Width="191px" >
< asp:ListItem Value="0" >Select < /asp:ListItem >
< asp:ListItem >--Select-- < /asp:ListItem >
< asp:ListItem >bb < /asp:ListItem >
< asp:ListItem >cc < /asp:ListItem >
< asp:ListItem >dd < /asp:ListItem >
< /asp:DropDownList >
< asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownList1" ErrorMessage="RequiredFieldValidator"
InitialValue="0" > < /asp:RequiredFieldValidator >

0 comments:

Post a Comment

About this blog

Blog Archive

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Blog Archive

Search This Blog