samedi 25 avril 2015

Adding a new column with buttons in gridview


I have added a button for Print in my gridview table as 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 help me with the c# code for this button. When the button is pressed I need it to redirect to a page (print.aspx) something like this. I have been trying the following code but it does not work . Please advise I need to create a new class etc . Thanks in advance for your help.

Session["id"] = GridView1.SelectedRow.Cells[0].Text;
Response.Redirect("Print.aspx");


Aucun commentaire:

Enregistrer un commentaire