validate Dropdownlist inside gridview using javascript
-
I use ASP.NET + C# In My form I have a Gridview inside gridview i use a dropdown list In dropdownlist it contain --Select-- and other items I want to add a validation to this dropdownlist so that the user must choose an item other than --Select-- I need to validate using javascript .How can i do that
-
I use ASP.NET + C# In My form I have a Gridview inside gridview i use a dropdown list In dropdownlist it contain --Select-- and other items I want to add a validation to this dropdownlist so that the user must choose an item other than --Select-- I need to validate using javascript .How can i do that
//if u have given selectedindex for your dropdownlist --select-- as 0 function error() { if ( document.getElementById('..._dropdownlist').selectedIndex = "0") alert('select atleast one'); } //but it will more easy if u provide a required field validator.
Padmanabhan
-
//if u have given selectedindex for your dropdownlist --select-- as 0 function error() { if ( document.getElementById('..._dropdownlist').selectedIndex = "0") alert('select atleast one'); } //but it will more easy if u provide a required field validator.
Padmanabhan
i will not work bcs i place the dropdownlist inside the gridview .
-
i will not work bcs i place the dropdownlist inside the gridview .
Add a javascript function through attributes.add in cs for(int i=0;i< gridview.rows.count;i++) { DropDownList ddl = (DropDownList)gridview.rows[i].cells[cellid].findcontrol('id'); ddl.attributes.add("onchange","return func("+ddl.clientid+");"); } Send the row id from the cs file function func(ddl) { //Do the validation in javascript } Hope that helps!!
I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--
-
I use ASP.NET + C# In My form I have a Gridview inside gridview i use a dropdown list In dropdownlist it contain --Select-- and other items I want to add a validation to this dropdownlist so that the user must choose an item other than --Select-- I need to validate using javascript .How can i do that
Please check yhe beolw script code function check(id) { var n=document.getElementById("grd"); var namecontrol=id.name; var myval=new Array(); var Arr=new Array(); myval=namecontrol.split("$") var rowindex=myval[1]; var j=rowindex if (document.getElementById("grd_"+j+"_ddl").value == '-- SELECT --') { alert("Please Select Sb Code.."); document.getElementById("grd_"+j+"_ddl").focus(); return false; } }