javascript - Getting the ID in of an ASP drop down list from client side -


what i'm trying 1 of drop down list change contents whenever selected item in 1 cahnges. have code in aspx file:

function modifyddlitems(id1, id2)  {     var ddlcontrolshown = document.getelementbyid(id1);     var ddlcontrolhidden = document.getelementbyid(id2);      if (ddlcontrolshown.options[ddlcontrolshown.selectedindex].value == "dd1")      {         //get number of items of hidden ddl         var length = ddlcontrolhidden.options.length;          //clear items of shown ddl         ddlcontrolshown.options.length = 0;          //add itmems of hidden ddl shown ddl         (i = 0; < length; i++)          {             ddlcontrolshown.options.add             var newoption = document.createelement("option")             newoption.text = ddlcontrolhidden.options[i].text;             newoption.value = ddlcontrolhidden.options[i].text.value;         }              }    } 

now, give front end id's thru this:

protected void setdd1confitems(gridviewrow gvrow, dataset baseconfitems) {     dataview dvconftype = new dataview(baseconfitems.tables[0]);     dataset dstemp = baseconfitems.clone();      dropdownlist ddlconftype2 = (dropdownlist)form1.findcontrol("ddlconftype2");     dropdownlist ddlba = (dropdownlist)gvrow.findcontrol("ddlba");     dropdownlist ddlconftype = (dropdownlist)gvrow.findcontrol("ddlconftype");      dvconftype.rowfilter = "ref_code = 'fax' or ref_code = 'eex' or ref_code = 'epd'";      dstemp.tables.clear();     dstemp.tables.add(dvconftype.totable());      ddlconftype2.datasource = dstemp;     ddlconftype2.databind();     //ddlba.attributes["onchange"] = "function getddld(" + ddlconftype.clientid + ", " + ddlconftype2.clientid + ") {modifyddlitems(id1, id2);}";     ddlba.attributes.add("onchange", "modifyddlitems('" + ddlconftype.clientid + "', '" + ddlconftype2.clientid + "')"); } 

when run it, vs keeps on telling me id1 , id2 both null, seems id's aren't passed client properly.

i think have code wrongly, first mistake found @ glance is,

you cannot find controls inside gridview using

gvrow.findcontrol("ddlba"); 

there may multiple rows in gridview, have find controls in each row of them have different clientids. first try replace below code

gvrow.rows[rowindex].findcontrol("controlid"); 

also, should written in kind of loop in order find rowindex value of grid.

describe exact requirement in brief. so, can in writing proper code.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -