c# - GridView RowCommand Events not firing when button created with an external class -


ok problem have grid need have paging on pages shown numbers want add 2 link button paging section alow user navigate next page prev page here code

protected void customergridview_rowcreated(object sender, gridviewroweventargs e) {     var grid = sender  gridview     if (e.row.rowtype == datacontrolrowtype.pager)     {         var prvlink = new linkbutton();         prvlink.text = "<";         prvlink.commandname = "page";         prvlink.commandargument = "prev";         prvlink.enableviewstate = true;         var nextlink = new linkbutton();         nextlink.text = ">";         nextlink.commandname = "page";         nextlink.commandargument = "next";         nextlink.enableviewstate = true;         var prvcell = new tablecell();         var nextcell = new tablecell();         prvcell.controls.add(prvlink);         nextcell.controls.add(nextlink);         table pagertable = e.row.controls[0].controls[0] table;         tablerow row = pagertable.rows[0];         row.cells.addat(0, prvcell);         row.cells.addat(row.cells.count, nextcell);         if (grid.pageindex == 0)         {             prvcell.enabled = false;         }         if (grid.pageindex == grid.pagecount - 1)         {             nextcell.enabled = false;         }     } } 

its working , users able navigate , forward (and can see grid rowcommand event getting fired)

the problem not want put code inside page (to make page tiny , put responsibility other class )

here class

public class gridstyler {     private gridview _grid;     public gridstyler(gridview grid)     {         _grid = grid;     }      public void addnextpreviousonpager()     {         _grid.rowcreated += _grid_rowcreated;     }      void _grid_rowcreated(object sender, gridviewroweventargs e)     {         var grid = sender gridview;         if (e.row.rowtype == datacontrolrowtype.pager)         {             var prvlink = new linkbutton();             prvlink.text = "<";             prvlink.commandname = "page";             prvlink.commandargument = "prev";             prvlink.enableviewstate = true;             var nextlink = new linkbutton();             nextlink.text = ">";             nextlink.commandname = "page";             nextlink.commandargument = "next";             nextlink.enableviewstate = true;              var prvcell = new tablecell();             var nextcell = new tablecell();             prvcell.controls.add(prvlink);             nextcell.controls.add(nextlink);             table pagertable = e.row.controls[0].controls[0] table;             tablerow row = pagertable.rows[0];             row.cells.addat(0, prvcell);             row.cells.addat(row.cells.count, nextcell);             if (grid.pageindex == 0)             {                 prvcell.enabled = false;             }             if (grid.pageindex == grid.pagecount - 1)             {                 nextcell.enabled = false;             }         }     }  } 

then should able call code in page load , should create link buttons , response click of them

var g = new gridstyler(customergridview); g.addnextpreviousonpager(); 

what happens link buttons created fine when user clicks them page refreshed rowcommand never fired (they fired of course when user clicks other buttons not 2 dynamically created buttons)

any suggestion appreciated

did @ similar "question" rowcommand not fire after clicking button

i found answer there!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -