weixin_36079422 2016-12-04 09:49 采纳率: 50%
浏览 1320
已采纳

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

  • threenewbee 2016-12-04 09:48
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料