asp.net - Adding a new column with buttons in gridview and binding data to it -


i have added button print in gridview table follows

<asp:gridview id="gridview1" runat="server" allowpaging="true"                      allowsorting="true" autogeneratecolumns="false" datakeynames="id"                      datasourceid="sqldatasource2"                      onselectedindexchanged="gridview1_selectedindexchanged" width="522px">                     <columns>                         <asp:boundfield datafield="id" headertext="id" insertvisible="false"                              readonly="true" sortexpression="id" />                         <asp:boundfield datafield="story_number" headertext="story_number"                              sortexpression="story_number" />                         <asp:boundfield datafield="date" headertext="date" sortexpression="date" />                         <asp:boundfield datafield="memory_card" headertext="memory_card"                              sortexpression="memory_card" />                         <asp:boundfield datafield="story_name" headertext="story_name"                              sortexpression="story_name" />                         <asp:buttonfield buttontype="button" text="print" />                     </columns>                 </asp:gridview> 

please me c# code button. when button pressed need redirect page (print.aspx). have been trying following code not work .thanks in advance help.

session["id"] = gridview1.selectedrow.cells[0].text; response.redirect("print.aspx"); 

instead of buttonfield, use template field

<asp:templatefield>     <itemtemplate>         <asp:imagebutton id="buttonprint" runat="server" cssclass="yourcssclassisneedit" onclick="printregfunction"             commandargument='<%# bind("id") %>' imageurl="images/button.png"/>     </itemtemplate> </asp:templatefield> 

your server code or behind code here:

protected void printregfunction(object sender, imageclickeventargs e)     {         session["id"] = ((imagebutton)sender).commandargument;         response.redirect("print.aspx");      } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -