asp.net - how to add button in gridview dynamically -


i creating gridview dynamically... want add buttons in , add relative rowcommand events. please me this. how create gridview's dynamically in code

for (int = 0; < dtemployees.rows.count; i++)             {                 tablerow tr = new tablerow();                 tablecell tc = new tablecell();                   gridview gv = new gridview();                 gv.id = "gv" + dttasks.rows[i]["taskid"].tostring() + dtemployees.rows[i]["empid"].tostring();                  datatable dt = dttasks.clone();                  foreach (datarow dr in dttasks.rows)                 {                     if (dr["empid"].tostring() == dtemployees.rows[i]["empid"].tostring())                     {                         dt.rows.add(dr.itemarray);                     }                 }                 gv.datasource = dt;                 gv.databind();                 tc.controls.add(gv);                 tr.cells.add(tc);                 tblmain.rows.add(tr);             } 

though don't test logically below:

if(e.row.rowindex > -1)  {      button button = new button();     button.commandargument = dt.rows[e.row.rowindex][i].tostring();      button.attributes.add("onclick", "button_clicked");      e.row.cells[i].controls.add(button); } 

where e gridviewroweventargs .and code placed in for/foreach loop.probably like..

for (int = 0; < gv.rows.count; i++) 

then make button event handler:

protected void button_clicked(object sender, eventagrs e) {    if (sender button)    {      try      {         string value = ((button)sender).commandargument;      }      catch      {        //check exception      }    } } 

also can view..


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -