how to use requiredfieldvalidator on dropdownlist in asp.net c#
Here I am solving the problem to
requiredfieldvalidator on dropdownlist We can solve this problem to use initial value of requiredfieldvalidator in asp.net.
Let’s take an example:-
Source Code:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<body>
<form id="form1" runat="server">
<div >
Nationality
<asp:DropDownList ID="ddlnation" runat="server" Height="25px" Width="133px">
<asp:ListItem Value="0" >select
the country</asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Sri
Lanka</asp:ListItem>
<asp:ListItem>England</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="rfvnation"
runat="server"
ControlToValidate="ddlnation" Display="Dynamic"
ErrorMessage="Please select the country" ForeColor="Red"
InitialValue="0"
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br />
<%--here i have
used button only for the postback--%>
<asp:Button ID="btnsubmit" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
Note:- if we will put the value of drop down list from design phase then you must need to give the
value of drop down manually that’s means
from source code
how to use requiredfieldvalidator on dropdownlist in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
7:51:00 PM
Rating:
No comments: