This Is my dropdown data getting from db
C#
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
Bash
.auto-style2 {
width: 420px;
}
function isValidfn() {
var TextBox1 = document.getElementById("");
var TextBox2 = document.getElementById("");
");
var RadioButton1 = document.getElementById("");
var RadioButton2 = document.getElementById("");--%>
var DropDownList1 = document.getElementById("");
");
var DropDownList3 = document.getElementById("");
var DropDownList4 = document.getElementById("");--%>
var TextBox3 = document.getElementById("");
var TextBox4 = document.getElementById("");
if (TextBox1.value == "") {
alert('First name Required');
return false;
}
else if (TextBox1.value.length 12) {
alert('Aadhar or Voter ID max length 12 numbers only');
}
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, '');
};
Back To Menu
First Name
Last Name
DoB
Gender
Qualification
State
City
Address Proof
Password
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 15, 2023, 11:32 AM EST
You can add asp:RequiredFieldValidator validator.
Example:
Refere below link:
https://www.aspsnippets.com/Articles/Using-RequiredFieldValidator-for-DropDownList-in-ASPNet.aspx
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 15, 2023, 10:05 AM EST
Hello Jaya,
You can add below code in isValidfn() function.
if (DropDownList1.selectedIndex == 0 || DropDownList1.value == "") { alert('Please select a Qualification'); return false; }Thanks
Naimish Makwana
Jaya PrakashRank #1,293 · 1.3K reputationPosted Feb 15, 2023, 11:15 AM EST
not working .. can u provide me in aspx.cs code sir
Diptiranjan SutarRank #1,236 · 1.4K reputationPosted Feb 16, 2023, 1:17 AM EST
Hello Jaya,
Please check below code for dropdownlist validation using RequiredFieldValidator.
Thanks,
Diptiranjan Sutar