将您的按钮放在模板字段中,并为其分配一个正常的点击事件,如下所示,
<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True">
<Columns>
<asp:BoundField HeaderText="field 1" />
<asp:BoundField HeaderText="field2" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" onclick="btnSelect_Click"
Text="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
您的点击事件如下所示
protected void btnSelect_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
GridViewRow r = (GridViewRow)b.NamingContainer;
////// once you have the row in which the event occured, you can do every thing with it
// like
int id = Convert.ToInt32(gvProducts.DataKeys[r.RowIndex].Value);
// or you can find control like
HiddenField hf = (HiddenField)r.FindControl("myHiddenField")
}