[local]1[/local]是不是这个样子 我想删除我的购物车中的物品,我就选择复选框,然后点击删除商品按钮,次按钮的单击事件代码如下: protected void btnDelete_Click1(object sender, EventArgs e)
{
CheckBox ck = new CheckBox();
string id = "";
List<int> listId = new List<int>();
//取出当前session中用户购物车中的记录
List<Goods_Order_Item> shopCart = Session["shopCart"] as List<Goods_Order_Item>;
List<Goods_Order_Item> delShopCart = new List<Goods_Order_Item>();
//获得用户将要删除的记录id
foreach (GridViewRow row in this.gvCart.Rows)
{
ck = (CheckBox)row.Cells[0].Controls[1];
if (ck.Checked)
{
id = row.Cells[1].Text;
listId.Add(int.Parse(id));
}
}
//遍历用户将要删除的记录id集合,查询出要删除的对象
foreach (int i in listId)
{
foreach (Goods_Order_Item item in shopCart)
{
if (item.GoodsId == i)
{
delShopCart.Add(item);
break;
}
}
}
//执行删除
foreach (Goods_Order_Item item in delShopCart)
{
shopCart.Remove(item);
}
//从新保存
Session["shopCart"] = shopCart;
//从新绑定
this.gvCart.DataSource = shopCart;
this.gvCart.DataBind();
}