asp.net - Button created in RowDatabound doesn't fire click event -


i adding linkbutton in gridview rowdatabound event , here firing click event on

        protected void cgvprojectpropertylist_rowdatabound(object sender, gridviewroweventargs e) {      if (e.row.rowtype == datacontrolrowtype.datarow)     {          linkbutton lnkdelete = new linkbutton();         lnkdelete.text = "delete";         e.row.cells[col_index_delete].controls.add(lnkdelete);         lnkdelete.commandname = "delete";          lnkdelete.click += new eventhandler(lnkdelete_click);     } }  void lnkdelete_click(object sender, eventargs e) {  } 

lnkdelete_click event not working.

thanks.

the problem caused fact adding linkbutton control dynamically, pretty painful approach in asp.net webforms.

in order events in asp.net work control has there after load event, because that's when control events fired. otherwise there isn't linkbutton bind click event to.

my suggestion try add linkbutton in markup instead. save lot of pain. can use rowcommand on gridview instead.

if isn't option, have add the linkbutton in load event , register handler click event there.

i have post using listview, using approach. should able learn that.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -