asp.net - Gridview findcontrol after dropdownlist event -
i want findcontrol on griview after ddl onselectedindexchanged event. target control on rowindex ddl located..
here codes;
protected void page_load(object sender, eventargs e) { arraylist dummysource = new arraylist() { "aa", "bb", "cc", "dd" }; if(!ispostback ) { gridview1.datasource = dummysource; gridview1.databind(); } } protected void ddlsample_onselectedindexchanged(object sender, eventargs e) { string valuecomponent = (sender dropdownlist).selecteditem.value; label1.text = valuecomponent; } int ddlvalue; protected void gridview1_onrowdatabound(object sender, gridviewroweventargs e) { //checking whether row data row if (e.row.rowtype == datacontrolrowtype.datarow) { //finding dropdown control. dropdownlist ddlsample = (dropdownlist)e.row.findcontrol("ddlsample"); label ilbldata = (label)e.row.findcontrol("lbldata"); if (ddlsample != null) { switch(ilbldata.text) { case "aa": ddlvalue = 2; break; case "bb": ddlvalue = 3; break; case "cc": ddlvalue = 4; break; case "dd": ddlvalue = 5; break; } (int = 1; <= ddlvalue; i++ ) { ddlsample.items.add(i.tostring() ); } } } } protected void gridview1_selectedindexchanged(object sender, eventargs e) { gridview gv = sender gridview; gv = gridview1; label foo = gv.selectedrow.findcontrol("lbldata") label ; label2.text = foo.text; }
the code value of dropdownlist selected item. i'm wondering on how component value in gridview. after selectedindexchange event of ddl
i made visual photo more clear http://i1288.photobucket.com/albums/b493/kasparov1/gridviewddl_zps3721fb97.png
thanks in advance;
try this
protected void ddlsample_onselectedindexchanged(object sender, eventargs e) { dropdownlist ddl = (dropdownlist)sender; label1.text = ddl.selecteditem.value; gridviewrow row = (gridviewrow)ddl.namingcontainer; // find control control control = row.findcontrol("mycontrol"); }
Comments
Post a Comment