private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { ArrayList gwlis = new ArrayList(); gwlis = (ArrayList)Session["gwshangping"]; int nI = int.Parse(e.Item.Cells[0].Text); for (int nJ = 0; nJ <= gwlis.Count - 1; nJ++) { Gouwu gw = new Gouwu(); gw = (Gouwu)gwlis[nJ]; if (gw.Shangpingid == nI) { money -= decimal.Parse(DataGrid1.Items[nJ].Cells[4].Text); gwlis.RemoveAt(nJ); } } Session["gwshangping"] = gwlis; shopbind(); count = DataGrid1.Items.Count; Label1.Text = money.ToString(); Label2.Text = count.ToString(); }
protected void ImageButton3_Click(object sender, ImageClickEventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('请先登陆!!!')</script>"); Session["gwshangping"] = null; Response.Write("<script>window.location='default.aspx'</script>"); } else { int nI = -1; try { nI = int.Parse(TextBox4.Text.Trim()); } catch (Exception) { Response.Write("<script>alert('购物数量只能为数字!')</script>"); } if (nI > 0) { Gouwu gw = new Gouwu(); gw.Shangpingid = int.Parse(Label2.Text); gw.Shangpingname = Label3.Text; gw.Price = Decimal.Parse(Label6.Text); gw.Quantity = nI; gw.Allprice = Decimal.Parse(Label6.Text) * nI; ArrayList gwlist = new ArrayList(); if (Session["gwshangping"] != null) { gwlist = (ArrayList)Session["gwshangping"]; } gwlist.Add(gw); Session["gwshangping"] = gwlist; Response.Redirect("shopping.aspx"); } else { Response.Write("<script>alert('不能为负数!')</script>"); } } }