Posted by : Anwar Hossain
Category : How to use different types of validation control using asp.net c#

How to use RequiredFieldValidator for DropDownList in ASP.NET C#

Dear Viewers I will show how to use how to use RequiredFieldValidator for DropDownList in ASP.NET C#. Sometimes we want to select at least one selection from DropDownList such situation RequiredFieldValidator can be easily used for validation. A submit button has been taken at the time of clicking on the submit button then an message will be displayed for warning.

RequiredFieldValidator for DropDownList

HTML

<html xmlns ="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DropDownList Validation using RequiredFieldValidator</title>
  <style type="text/css">
  .style1
  {
  width: 250px;
  }
  </style>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <table width="45%" bgcolor="#B3D9D9">
  <tr>
  <td style="color: Red;" class="style1">
  <h3>
  DropDownList Validation using RequiredFieldValidator
  </h3>
  </td>
  </tr>
  <tr>
  <td class="style1">
  <asp:DropDownList ID="drpCountry" runat="server">
  <asp:ListItem Value="0" Selected="true">Select Your Country</asp:ListItem>
  <asp:ListItem Value="1">Bangladesh</asp:ListItem>
  <asp:ListItem Value="2">Indian</asp:ListItem>
  <asp:ListItem Value="3">China</asp:ListItem>
  <asp:ListItem Value="4">Japan</asp:ListItem>
  <asp:ListItem Value="5">Pakistan</asp:ListItem>
  <asp:ListItem Value="6">Maldives</asp:ListItem>
  </asp:DropDownList>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ForeColor="#FF0000" ErrorMessage="Select Your Country"
  ControlToValidate="drpCountry" InitialValue="0" EnableClientScript="False" runat="server" />
  </td>
  </tr>
  <tr>
  <td align="center" class="style1">
  &nbsp;
  </td>
   </tr>
  <tr>
  <td align="left" class="style1">
  <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
  </td>
  </tr>
  <tr>
  <td align="center" class="style1">
  &nbsp;
  </td>
  </tr>
  </table>
  <br />
  </div>
  </form>
</body>
</html>

Out Put

RequiredFieldValidator-for-dropdownlist ASP.NET C#



Realted Article Headline

How to use RequiredFieldValidator for RadioButtonList in ASP.NET C#
How to use RequiredFieldValidator for DropDownList in ASP.NET C#
How to use RangeValidator in ASP.NET C#
how to use RequiredFieldValidator in ASP.NET C#
How to use RegularExpressionValidator Control in ASP.NET using C#
How to use Custom Validator control using asp.net c#
How to use compare validation control using asp.net c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection