解决方法如下:
1、先在GridView中添加一模板列,编辑模板,然后添加一按钮,设置commandName和CommandArgument属性如下:
<asp:ImageButton id="Imagebutton1" runat="server" ImageUrl="images/go2_buy.jpg" CommandName="AddCart" CommandArgument= <%# Eval("pid") %> >//pid 为主键
</asp:ImageButton>
2、接着,结束模板编辑,选中gridview,在属性面板处点“N”事件,在Rowcommand事件处双击并添加代码,如下:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)//点击购买后
{
if (e.CommandName == "AddCart")//如果传来的命名名字中是AddCart,就添加产品
{
//用户选中一件产品后,默认订一件产品
string pid1 = e.CommandArgument.ToString();
Response.Write(pid1);
Response.End();
....//添加其它更多代码
}
}
1、先在GridView中添加一模板列,编辑模板,然后添加一按钮,设置commandName和CommandArgument属性如下:
<asp:ImageButton id="Imagebutton1" runat="server" ImageUrl="images/go2_buy.jpg" CommandName="AddCart" CommandArgument= <%# Eval("pid") %> >//pid 为主键
</asp:ImageButton>
2、接着,结束模板编辑,选中gridview,在属性面板处点“N”事件,在Rowcommand事件处双击并添加代码,如下:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)//点击购买后
{
if (e.CommandName == "AddCart")//如果传来的命名名字中是AddCart,就添加产品
{
//用户选中一件产品后,默认订一件产品
string pid1 = e.CommandArgument.ToString();
Response.Write(pid1);
Response.End();
....//添加其它更多代码
}
}
浙公网安备 33010602011771号