小弟现在在做一购物系统.
1.没有会员系统,怎么连续购物?
2.就是在结算的时,怎么去实现购物车里面的更新,等等,里面的数据都放在那里???望那位大哥,可以帮助我一下.
十分感谢!

解决方案 »

  1.   

    那是到seesion里面还是cookie里面还是?
      

  2.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    BindGrid();
    }
    // 在此处放置用户代码以初始化页面
    }
    private void BindGrid()
    {
    SqlDataAdapter da=new SqlDataAdapter("select * from products",@"server=ITBU;uid=sa;pwd=;database=ywtable");
    DataSet ds=new DataSet();
    da.Fill(ds,"products"); DataGrid1.DataSource=ds;
    DataGrid1.DataBind();
    }
    public int Add(CShoppingCartItem item)
    {
    ArrayList arr;
    if(HttpContext.Current.Session["mycart"]!=null)
    {
    arr=(ArrayList)HttpContext.Current.Session["mycart"];
    }
    else
    {
    arr=new ArrayList();
    HttpContext.Current.Session["mycart"]=arr;
    }
    arr.Add(item);
    return 0;
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
    this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
    this.button1.Click += new System.EventHandler(this.button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
    {

    } private void button1_Click(object sender, System.EventArgs e)
    {
    Response.Redirect("cart.aspx");
    } private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    CShoppingCartItem cart=new CShoppingCartItem(int.Parse(e.Item.Cells[0].Text),e.Item.Cells[1].Text,decimal.Parse(e.Item.Cells[2].Text),int1);
    Add(cart);
    BindGrid();
    }
      

  3.   

    public class CShoppingCartItem
    {
    private int intProductID;
    private string strProductName;
    private decimal decUnitPrice;
    private int intQuantity;

    public CShoppingCartItem(int intProductID,string strProductName,decimal decUnitPrice,int intQuantity)
    {
    ProductID   = intProductID;
    ProductName = strProductName;
    UnitPrice   = decUnitPrice;
    intQuantity = Quantity;
    }
    public int ProductID
    {
    get
    {
    return intProductID;
    }
    set
    {
    intProductID=value;
    }
    } public string ProductName
    {
    get
    {
    return strProductName;
    }
    set
    {
    strProductName=value;
    }
    } public decimal UnitPrice
    {
    get
    {
    return decUnitPrice;
    }
    set
    {
    decUnitPrice=value;
    }
    } public int Quantity
    {
    get
    {
    return intQuantity;
    }
    set
    {
    intQuantity=value;
    }
    } }
      

  4.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    FillCartFromSession();
    }
    // 在此处放置用户代码以初始化页面
    } public int Remove(CShoppingCartItem item)
    {
    ArrayList items=(ArrayList)HttpContext.Current.Session["mycart"];
    for(int i=0;i<items.Count;i++)
    {
    if(((CShoppingCartItem)items[i]).ProductID==item.ProductID)
    {
    items.RemoveAt(i);
    break;
    }
    }
    return 0;
    }

    public System.Collections.ArrayList GetItems()
    {
    return (ArrayList)HttpContext.Current.Session["mycart"];
    } private void FillCartFromSession()
    {
    CShoppingCartItem AllItem = null;
    ArrayList AllList = GetItems(); 
    DataGrid1.DataSource=AllList;
    DataGrid1.DataBind();

    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
    this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    Response.Redirect("WebForm1.aspx");
    } private void Button2_Click(object sender, System.EventArgs e)
    {
    //now you can iterate through cookies collection
    //and DataGrid and get details of all items
    //then add your code here to insert into database
    } private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    CShoppingCartItem cart=new CShoppingCartItem(int.Parse(e.Item.Cells[0].Text),e.Item.Cells[1].Text,decimal.Parse(e.Item.Cells[2].Text),int.Parse(e.Item.Cells[3].Text));
    Remove(cart);
    FillCartFromSession();
    这是存到SESSION的,我也是新手,借鉴别人的
      

  5.   

    把DataSet保存到Session里。或者你建个数据集DataSet.xsd。当你要更新购物车时重新绑定一下就行了。