首页上一页 1  下一页尾页 1 条记录 1/1页
        购物车Hashtable问题(急)
                 	
                        发表在ASP.NET图书答疑
                        2010-11-27                                                
                    		
                                                                            	
                        
                        
                    
                    
                    	是否精华
                    	是
                    	否
                    
                    
                    
                            版块置顶:
                            是
                            否
                        
                    
                                           我买了你们的书,在购物网站我在物品的详细页设置了按钮购物,代码如下:
protected void byImage_Click(object sender, ImageClickEventArgs e)
{
/*判断是否登录*/
ST_check_Login();
Hashtable hashCar;
if (Session["ShopCart"] == null)
{
//如果用户没有分配购物车
hashCar = new Hashtable(); //新生成一个
hashCar.Add(Convert.ToInt32(Request["id"].Trim()), 1); //添加一个商品
hashCar.Add(this.txtYs.Text,"yanse");
Session["ShopCart"] = hashCar; //分配给用户
}
else
{
//用户已经有购物车
hashCar = (Hashtable)Session["ShopCart"];//得到购物车的hash表
if (hashCar.Contains(Convert.ToInt32(Request["id"].Trim())))//购物车中已有此商品,商品数量加1
{
int count = Convert.ToInt32(hashCar[Convert.ToInt32(Request["id"].Trim())].ToString());//得到该商品的数量
hashCar[Convert.ToInt32(Request["id"].Trim())] = (count + 1);//商品数量加1
}
else
{
hashCar.Add(Convert.ToInt32(Request["id"].Trim()), 1);//如果没有此商品,则新添加一个项
hashCar.Add(this.txtYs.Text, "yanse");
}
}
}
在购物车中还是原来的代码
foreach (object key in hashCar.Keys)
{
row = dtTable.NewRow();
row["BookID"] = key.ToString();
row["Num"] = hashCar[key].ToString();
dtTable.Rows.Add(row);
}
这个是读取
现在我在购物页多了个颜色选择,比如 yanse ,我怎么把他加进去.
                
        	
        
        
    protected void byImage_Click(object sender, ImageClickEventArgs e)
{
/*判断是否登录*/
ST_check_Login();
Hashtable hashCar;
if (Session["ShopCart"] == null)
{
//如果用户没有分配购物车
hashCar = new Hashtable(); //新生成一个
hashCar.Add(Convert.ToInt32(Request["id"].Trim()), 1); //添加一个商品
hashCar.Add(this.txtYs.Text,"yanse");
Session["ShopCart"] = hashCar; //分配给用户
}
else
{
//用户已经有购物车
hashCar = (Hashtable)Session["ShopCart"];//得到购物车的hash表
if (hashCar.Contains(Convert.ToInt32(Request["id"].Trim())))//购物车中已有此商品,商品数量加1
{
int count = Convert.ToInt32(hashCar[Convert.ToInt32(Request["id"].Trim())].ToString());//得到该商品的数量
hashCar[Convert.ToInt32(Request["id"].Trim())] = (count + 1);//商品数量加1
}
else
{
hashCar.Add(Convert.ToInt32(Request["id"].Trim()), 1);//如果没有此商品,则新添加一个项
hashCar.Add(this.txtYs.Text, "yanse");
}
}
}
在购物车中还是原来的代码
foreach (object key in hashCar.Keys)
{
row = dtTable.NewRow();
row["BookID"] = key.ToString();
row["Num"] = hashCar[key].ToString();
dtTable.Rows.Add(row);
}
这个是读取
现在我在购物页多了个颜色选择,比如 yanse ,我怎么把他加进去.

 
	
                                                 VIP会员
VIP会员 购物车
购物车

 私信
                         私信 
                     发表新帖
发表新帖 立即签到
立即签到 
        		  
        		 
         		 关注
关注
                  回复
 回复 支持(
                	支持( 反对(
                    反对( 
                







 
                     
                     
					 
						 
						 
						 
						