ASP.net购物车 session datatable

CS1061: “System.Web.UI.WebControls.GridViewRowCollection”不包含“Cells”的定义,并且找不到可接受类型为“System.Web.UI.WebControls.GridViewRowCollection”的第一个参数的扩展方法“Cells”(是否缺少 using 指令或程序集引用?)

 protected void Page_Load(object sender, EventArgs e)
{
    if (Session["shoppingcart"] == null)
    {
        Response.Write("<script>alert('购物车为空,请挑选商品');window.location.href='Default.aspx';</script>");
    }
    else
    {
        if (!this.IsPostBack)
        {
            GridView1.DataSource = Session["shoppingcart"];
            GridView1.DataBind();
            double sum = 0.0;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {

                sum = sum + (double.Parse(GridView1.Rows.Cells[2].Text));

            }
            Label2.Text = "总计:" + sum.ToString() + "元";
        }
    }
}

protected void ImageButton14_Click(object sender, ImageClickEventArgs e)
{
Session.Remove("shoppingcart");
GridView1.DataBind();
Label2.Text = "总计:0元";
}
protected void ImageButton15_Click(object sender, ImageClickEventArgs e)
{
string name = Session["UserName"].ToString();//获得提交用户的用户名
double sum = 0.0;
string p1="";
string p2="";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
sum = sum + (double.Parse(GridView1.Rows.Cells[2].Text));
p1 =GridView1.Rows.Cells[0].Text;
p2 =GridView1.Rows.Cells[1].Text;
}

    BookDataContext w = new BookDataContext();
    Cart dan = new Cart();
    dan.UserName = name;
    dan.BookName= p1;
    dan.BookId = p2;
    dan.Price = sum;
    dan.addtime = Convert.ToDateTime(DateTime.Now);
    w.Cart.InsertOnSubmit(dan);
    w.SubmitChanges();

}
}

1个回答

GridView1.Rows[第n-1行].Cells[2].Text

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!