This Is my dropdown data getting from db
void GetQualification() { con.Open(); SqlDataAdapter da = new SqlDataAdapter("sp_GetQ", con); DataSet ds = new DataSet(); da.Fill(ds); DropDownList1.DataSource = ds; DropDownList1.DataTextField = "cname"; DropDownList1.DataValueField = "cname"; DropDownList1.DataBind(); DropDownList1.Items.Insert(0, "Select Qualification"); con.Close(); }
How can i validate through asp.net or
this is my javascript code validation for dropdown is not working pls help me
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="MasterLogin.Registration" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <style type="text/css"> .auto-style2 { width: 420px; } </style> <script type="text/javascript"> function isValidfn() { var TextBox1 = document.getElementById("<%=TextBox1.ClientID %>"); var TextBox2 = document.getElementById("<%=TextBox2.ClientID %>"); <%-- var Calendar1 = document.getElementById("<%=Calendar1.ClientID %>"); var RadioButton1 = document.getElementById("<%=RadioButton1.ClientID %>"); var RadioButton2 = document.getElementById("<%=RadioButton2.ClientID %>");--%> var DropDownList1 = document.getElementById("<%=DropDownList1.ClientID %>"); <%-- var DropDownList2 = document.getElementById("<%=DropDownList2.ClientID %>"); var DropDownList3 = document.getElementById("<%=DropDownList3.ClientID %>"); var DropDownList4 = document.getElementById("<%=DropDownList4.ClientID %>");--%> var TextBox3 = document.getElementById("<%=TextBox3.ClientID %>"); var TextBox4 = document.getElementById("<%=TextBox4.ClientID %>"); if (TextBox1.value == "") { alert('First name Required'); return false; } else if (TextBox1.value.length < 4) { alert('first min length 4 letters'); } if (TextBox2.value == "") { alert('Last Name Required'); } else if (TextBox2.value.length < 3) { alert('last name min 3 letters') } else if (TextBox3.value.length < 12) { alert('Aadhar or Voter ID min length 12 numbers only'); } else if (TextBox3.value.length > 12) { alert('Aadhar or Voter ID max length 12 numbers only'); } else if (TextBox4.value.length < 12) { alert('password min length 12 numbers'); } else if (TextBox4.value.length > 12) { alert('password max length 12 letters'); } } //function CheckDropDownList() { // if (document.getElementById('DropDownList1').selectedIndex = 0) // alert('Please Select City'); //} var digits = function (box) { box.value = box.value.replace(/[^0-9]/g, ''); }; </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <table class="auto-style1"> <asp:HyperLink ID="hl" runat="server" NavigateUrl="~/Menu.aspx"> Back To Menu</asp:HyperLink> <tr> <td class="auto-style2">First Name</td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2">Last Name</td> <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2">DoB</td> <td> <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar> </td> </tr> <tr> <td class="auto-style2">Gender</td> <td> <asp:RadioButton ID="RadioButton1" runat="server" GroupName="g" Text="M" /> <asp:RadioButton ID="RadioButton2" runat="server" GroupName="g" Text="F" /> </td> </tr> <tr> <td class="auto-style2">Qualification</td> <td> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </td> </tr> <tr> <td class="auto-style2">State</td> <td> <asp:DropDownList ID="DropDownList2" runat="server" Height="16px"> </asp:DropDownList> </td> </tr> <tr> <td class="auto-style2">City</td> <td> <asp:DropDownList ID="DropDownList3" runat="server"> </asp:DropDownList> </td> </tr> <tr> <td class="auto-style2">Address Proof</td> <td> <asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged"> <asp:ListItem Text="Select Proof" /> <asp:ListItem Text="Aadhar" Value="AadharCard" /> <asp:ListItem Text="VoterId" Value="VoterId" /> </asp:DropDownList> <asp:TextBox ID="TextBox3" Visible="false" onkeyup="digits(this)" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2">Password</td> <td> <asp:TextBox ID="TextBox4" onkeyup="digits(this)" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2"> <asp:Button ID="Button1" runat="server" OnClientClick="return isValidfn()" OnClick="Button1_Click" Text="Save" /> </td> <td> </td> </tr> <tr> <td class="auto-style2"> </td> <td> </td> </tr> <tr> <td class="auto-style2"> </td> <td> </td> </tr> </table> </asp:Content>