有没有人有任何帮助,我正在使用 Arraylist 在会话中存储详细信息。当将物品添加到购物车时,我希望能够拥有一些功能,我从删除按钮开始(最终我也想要一个编辑按钮)所以我尝试了两种删除按钮的方法,但都不适合我,第一次尝试:
sc.aspx 页面
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" CommandArgument='<%# ((GridViewRow)Container).RowIndex %>' CommandName="deleterow" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>'
和:
'onrowcommand="DeleteRowBtn_Click"'
sc.aspx.cs
'protected void DeleteRowBtn_Click(object sender, GridViewCommandEventArgs e)
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
}'
第二次尝试:
sc.aspx
'OnRowDeleting="GridView1_RowDeleting"'
'<asp:CommandField ShowDeleteButton="True" />'
sc.aspx.cs
'protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
ArrayList remove = (ArrayList)Session["aList"];
DataRow dr = remove.Rows[e.RowIndex];
remove.Rows.Remove(dr);
GridView1.EditIndex = -1;
FillShopCart();
}'