您可以使用命令参数来确定单击了哪一行(假设您在一行中有多个按钮(标准按钮/链接按钮)
<asp:GridView OnRowCommand="GridViewOnItemCommand" runat="server">
<asp:TemplateField HeaderText="Details">
<ItemTemplate>
<asp:LinkButton ID="btnDetails" CommandName="Details" CommandArgument="YOUR_COMMAND_ARG_HERE" Text="Details" runat="server"/>
<asp:LinkButton ID="btnDelete" CommandName="Delete" CommandArgument="YOUR_COMMAND_ARG_HERE" Text="Delete" runat="server"/>
<ItemTemplate>
</asp:TemplateField>
</asp:GridView>
在文件后面的代码中
protected void GridViewOnItemCommand(object sender, GridViewCommandEventArgs e)
{
//you can determine which button was clicked (detail or delete)
var command = e.CommandName;
//you can determine which row was clicked
var arg = e.CommandArgument;
if(command == "Details")
ShowDetails(arg);
if(command == "Delete")
Delete(arg);
}
希望这可以帮助