用asp.net怎么将用checkbox选购的商品放入到购物车中啊? 谢谢!
我知道可以用session,可是写了之后没有反应System.Data.DataTablecart=newSystem.Data.DataTable();for(inti...
我知道可以用session,可是写了之后没有反应
System.Data.DataTable cart = new System.Data.DataTable();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cc = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (cc.Checked)
{
if (Session["shopping cart"] == null)
{
cart.Columns.Add("商品编号", typeof(int));
cart.Columns.Add("商品名称", typeof(string));
cart.Columns.Add("单元含量", typeof(string));
cart.Columns.Add("单价", typeof(double));
Session["shopping cart"] = cart;
}
cart = (System.Data.DataTable)Session["shopping cart"];
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
string bhText = row.Cells[2].Text;
string mcText = row.Cells[3].Text;
string djText = row.Cells[6].Text;
int bh = int.Parse(bhText);
double dj = double.Parse(djText);
System.Data.DataRow rr = cart.NewRow();
rr["商品编号"] = bh;
rr["商品名称"] = mcText;
rr["单价"] = dj;
cart.Rows.Add(rr);
Session["shoppingcart"] = cart;
}
} 展开
System.Data.DataTable cart = new System.Data.DataTable();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cc = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (cc.Checked)
{
if (Session["shopping cart"] == null)
{
cart.Columns.Add("商品编号", typeof(int));
cart.Columns.Add("商品名称", typeof(string));
cart.Columns.Add("单元含量", typeof(string));
cart.Columns.Add("单价", typeof(double));
Session["shopping cart"] = cart;
}
cart = (System.Data.DataTable)Session["shopping cart"];
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
string bhText = row.Cells[2].Text;
string mcText = row.Cells[3].Text;
string djText = row.Cells[6].Text;
int bh = int.Parse(bhText);
double dj = double.Parse(djText);
System.Data.DataRow rr = cart.NewRow();
rr["商品编号"] = bh;
rr["商品名称"] = mcText;
rr["单价"] = dj;
cart.Rows.Add(rr);
Session["shoppingcart"] = cart;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询