ASP.NET - validation for dropdown - Asked By msakt on 08-Jun-12 04:21 AM

validation for dropdown when click checkbox inside gridview
Jitendra Faye replied to msakt on 08-Jun-12 04:30 AM
Try like this-

<script type="text/javascript">

function funCheck(src, args) {
var val= document.getElementById('<%=ddl1.ClientID %>');
if (val.value="") //Here u are checking any of the DDL is not selected
alert("select any value");


dipa ahuja replied to msakt on 08-Jun-12 04:39 AM
 <asp:DropDownList ID="ddlaccesstype" runat="server" ValidationGroup="Chk" Width="171px">
    <asp:ListItem Text="--Select--" Value="0"></asp:ListItem>
    <asp:ListItem Text="Admin" Value="1"></asp:ListItem>
    <asp:ListItem Text="Supervisor" Value="2"></asp:ListItem>      
<asp:RequiredFieldValidator ID="reqFavoriteColor" Text="(Required)" InitialValue="0"
    ControlToValidate="ddlaccesstype" runat="server" />
Using javascript
<script type="text/javascript">
  function Validate() {
    var ddl = document.getElementById('<%=DropDownList1.ClientID%>');
    var option = ddl.options[ddl.selectedIndex];
    if (option.value == 0) {
      alert('select value from dropdown');
      return false;
    else {
      return true;
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return Validate();" />