weixin_36079422
weixin_36079422
采纳率50%
2016-12-04 09:49

ASP.net购物车 session datatable

10
已采纳

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条回答

相关推荐