validation inside gridview using javascipt

Ankit tewari
Ankit t...
40 Points
20 Posts

sir, i how can i validate single dropdown inside gridview... 

i have use this code,

function Validate() {

var flag = true;
var dropdowns = new Array(); //Create array to hold all the dropdown lists.
var gridview = document.getElementById('<%=gv_accounting.ClientID%>'); //GridView1 is the id of ur gridview.
dropdowns = gridview.getElementsByTagName('select'); //Get all dropdown lists contained in GridView1.
for (var i = 0; i < dropdowns.length; i++) {
if (dropdowns.item(i).value == '0') //If dropdown has no selected value
flag = false;
break; //break the loop as there is no need to check further.
if (!flag) {
alert('Please select value in each dropdown');
return flag;



but problem is this..the validation working on all dropdown..but i want use this validation on single dropdown..


Views: 9111
Total Answered: 1
Total Marked As Answer: 0
Posted On: 13-Dec-2015 00:56

Share:   fb twitter linkedin
Rahul Maurya
Rahul M...
1402 Points
236 Posts

Hi Ankit,

On Gridview rowdatabound event add an attribute onchange as : 

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
DropDownList ddl = new DropDownList();
ddl=(DropDownList) e.Row.FindControl("ddlID");
ddl.Attributes.Add("onblur", "onchangemethodValidate(this);");

 And Aspx page: 

function onchangemethodValidate(ddl){
Posted On: 13-Dec-2015 03:20
 Log In to Chat