程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> asp.net-ASP.net購物車 session datatable

asp.net-ASP.net購物車 session datatable

編輯:編程解疑
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();

}
}

最佳回答:


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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved