您需要这样处理OnRowCommand
gridview 上的事件:
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView_RowCommand"
并创建一个 ItemTemplateField 来显示常规<asp:button>
而不是使用ButtonField
列:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn" runat="server"
CommandName="Something" CommandArgument='<%#Eval("id_p") %>'
Text="Stavi u košaricu" />
</ItemTemplate>
</asp:TemplateField>
现在您处理 RowCommand 事件:
protected void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
string m_id = e.CommandArgument.ToString();
if (e.CommandName == "Something")
{
//do something with m_id
}
}