0

我有一个 Gridview 如下:

<asp:GridView ID="PartnerView" runat="server" AllowPaging="True" 
                       AllowSorting="True" AutoGenerateColumns="False" CssClass="GridViewStyle" 
                       GridLines="None" DataKeyNames="Partnerid" Width="900px"> 
  <Columns>
                            <asp:BoundField DataField="Partnername" HeaderText="Partner Name" />
                            <asp:BoundField DataField="partnertype" HeaderText="Type"/>
                            <asp:BoundField DataField="Contact" HeaderText="Contact" />
                            <asp:BoundField DataField="City" HeaderText="City"/> 
                            <asp:BoundField DataField="State" HeaderText="State"/>
                            <asp:BoundField DataField="Country" HeaderText="Country" />
                            <asp:BoundField DataField="email" HeaderText="Email ID" />
                            <asp:TemplateField HeaderText="Details">
                                      <ItemTemplate>
                                                <asp:LinkButton ID="Show_Button" Text="Show" runat="server" OnClick="Show_Button_click"></asp:LinkButton>                                          
                                      </ItemTemplate>    
                            </asp:TemplateField>
                        </Columns> 
            </asp:GridView>

我在gridview中有LinkBUtton ....现在我想要当我单击gridview中的LinkBUtton时,我只想获取该特定行的数据......在下一页..

4

1 回答 1

1

您可以通过 LinkBut​​ton 的 NamingContainer 获得 GridViewRow:

protected void Show_Button_click(Object sender, EventArgs e)
{
    LinkButton Show_Button = (LinkButton)sender;
    GridViewRow row = (GridViewRow)Show_Button.NamingContainer;
    // now you can get all other fields via FindControl(in case it's a TemplateField)
    //  or via row.Cells[index].Text
    // Then Response.Redirect to the other page and pass appropriate URL-Parameters
}
于 2012-04-23T12:24:29.387 回答