在网上找了一些代码 都很乱的  我要做个用session保存的购物车源码

解决方案 »

  1.   

    http://download.csdn.net/source/1141954http://topic.csdn.net/u/20071122/14/d2a0961f-d9e2-4bdc-a0ed-3d1c27fb2597.html
      

  2.   

    http://topic.csdn.net/u/20081206/13/922552C1-393E-4D8B-B1F9-E5F73E4BB4F8.html
      

  3.   

    给你个参考Dictionary<string, OrdersInfo> dic = new Dictionary<string, OrdersInfo>();
                if (ViewState["car"] != null)
                {
                    dic = ViewState["car"] as Dictionary<string, OrdersInfo>;
                }            for (int i = 0; i < this.GridView1.Rows.Count; i++)
                {
                    CheckBox checkbox = (CheckBox)this.GridView1.Rows[i].FindControl("ckbbuy");
                    if (checkbox.Checked)
                    {
                        string no = ((Label)GridView1.Rows[i].FindControl("lblno")).Text;//编号
                        string tbxText = ((TextBox)GridView1.Rows[i].FindControl("txtbz")).Text;//备注
                        string num = ((TextBox)GridView1.Rows[i].FindControl("txtnum")).Text;//数量
                        string check = ((RadioButtonList)GridView1.Rows[i].FindControl("RadioButtonList1")).SelectedItem.Text;//单位
                        //string type = ((Label)GridView1.Rows[i].FindControl("lblprotype")).Text;//规格                    int dd = 0;
                        if (int.TryParse(num, out dd) && Convert.ToInt32(num) > 0)
                        {
                            if (dic.ContainsKey(no))//如果购物车已存在该商品,更新数量和单位
                            {
                                Dictionary<string, OrdersInfo>.ValueCollection orin = dic.Values;
                                foreach (OrdersInfo oi in orin)
                                {
                                    if (oi.ProductID == no)//更新当前匹配的记录
                                    {
                                        oi.ProductNum = dd;//更新数量
                                        oi.ProductUnit = check;//更新单位
                                        oi.ProductDescribe = tbxText;//更新备注
                                    }
                                }
                            }
                            else//不存在就直接添加进购物车
                            {
                                OrdersInfo oi = new OrdersInfo();
                                oi.ProductID = no;
                                oi.ProductNum = Convert.ToInt32(num);
                                oi.ProductUnit = check;
                                oi.ProductDescribe = tbxText;
                                //oi.OrdersInfoID = 1;// type;//将详单编号当规格存储                            dic.Add(oi.ProductID, oi);//保存当前有备注的订单信息
                            }
                        }
                        if (dic.Count > 0)
                        {
                            ViewState["car"] = dic;//购物车
                        }
                    }
                }
      

  4.   

    我在大2的时候写了一个泛型的购物车 也是用SESSION
    在CSDN有链接,现在被转到其他网站了 也可以下载下载
      

  5.   

    http://www.51aspx.com/S/购物车.html  51  源码 找到的,你去看下
      

  6.   

    我做的
    ASP.NET购物车(源码下载)
      

  7.   

    用session做购物车,是非常不明智的做法。
    用数据库来做,非常之简单,又好用。