c# - Row Command Event not fired for Dynamically created buttons inside gridView -


i have gridview in dynamically creating label , button on gv_rowdatabound.

.cs

label tagvalue = new label(); tagvalue.id = "lbltags_"+i; //tagvalue.cssclass = "tagbubble tagbubbledelete"; tagvalue.text = tag;  button delete = new button(); delete.id = "btndelete_" + i; delete.tooltip = "delete"; delete.cssclass = "tagbubbledelete"; delete.commandname = "delete"; delete.commandargument = imageid.text; 

the problem "rowcommand" function not getting fired. not able reach e.commandname=="delete".

what can done fire rowcommand event dynamically created button inside gridview.

any appreciated.

*******edit

.aspx

 <asp:gridview runat="server" id="mygv" allowsorting="false" allowpaging="false"                         pagesize="20" autogeneratecolumns="false"                            datasourceid="ldsgv"                          ondatabound="gv_databound"                         onrowdatabound="gv_rowdatabound"                         onrowcommand="gv_rowcommand"                         >   <asp:templatefield headertext="details" headerstyle-cssclass="nosort"                                     itemstyle-cssclass="fieldaligncenter">                                     <itemtemplate>                                       <div class="alignleft margintop5 float-l" id="tags" runat="server"                         style="clear:both">                                           //**here adding dynamic buttons                                           </div>                                        </itemtemplate>                                      </asp:templatefield>                                 </asp:gridview> 

the problem creating button gv_rowdatabound event , when click on button page gets reloaded , button not created time because have written code in gv_rowdatabound event.so button wil not work because there no button!.

you should try this

protected void page_init(object sender, eventargs e)     {         gridview1.databind(); //key code     }      protected void gv_databound(object sender, eventargs e)     {                  button delete = new button();                delete.id = "btndelete_" + i;                 delete.tooltip = "delete";                delete.cssclass = "tagbubbledelete";                delete.commandname = "delete";                delete.commandargument = imageid.text;       }      protected void gv_rowcommand(object sender, commandeventargs e) //your grid view function change accroding need!!     {         if (e.commandname == "delete")         {          }     } 

i not sure work 100% @ least shuld try this

update

if binding gridview @ page_load have use code

 protected void page_load(object sender, eventargs e)         {            if (!ispostback)             {             yourgridviewbindcode(); //key code             }               } 

because if every time bind gridview may cancel out effect of button click!


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -