我有一个gridview,每行都有按钮:
按钮位于模板字段中:
<asp:GridView ID="storyGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"
CellSpacing="2" DataKeyNames="PK_NonScrumStory" DataSourceID="SqlDataSource1">
...
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:Button ID="viewHoursButton" runat="server" Text="View Hours" OnClick="viewHoursButton_OnClick" />
<asp:Button ID="addHoursButton" runat="server" Text="Add Hours" OnClick="addHoursButton_OnClick" />
<asp:Button ID="editButton" runat="server" Text="Edit" OnClick="editButton_OnClick" />
<asp:Button ID="deleteButton" runat="server" Text="Delete" OnClick="deleteButton_OnClick" />
</ItemTemplate>
</asp:TemplateField>
如何在点击时获取数据键名?
protected void viewHoursButton_OnClick(object sender, EventArgs e)
{
//get PK_NonScrumStory for clicked row
}