你将购买记录放在数组中,然后将这个数组采用session保存起来,会更好一些。

解决方案 »

  1.   

    使用HashTable,一般都是使用Session的
      

  2.   

    http://www.aspcool.com/lanmu/browse1.asp?ID=1070&bbsuser=aspnet
    如果你要用httpcookies看看这个。
      

  3.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
    Hashtable ht = (Hashtable)Session["myCart"];
    if(ht==null)
    {
    ht = new Hashtable();
    ht.Add(TextBox1.Text,TextBox2.Text);
    }
    else
    {
    if(ht[TextBox1.Text]==null)
    {
    ht.Add(TextBox1.Text,TextBox2.Text);
    }
    else
    {
    ht[TextBox1.Text] = Convert.ToInt32(ht[TextBox1.Text])Convert.ToInt32(TextBox2.Text);
    }
    }
    Session["myCart"] = ht;
    Response.Write("<script>alert('"+ht[TextBox1.Text].ToString()+"');</script>");
    }
      

  4.   

    为什么这样写,我在本地的硬盘下看不到Cookie文件呢?
    也就是说下面的代码,无法在本地硬盘上建立Cookie。
    请看错误在哪呢?
    我把系统放置Cookie里的文件全部删除。然后跑下面的代码,发现在机器上并没有建立Cookie 请问为什么呢?private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    int BookId;
    HttpCookie cookie;
    if(!Page.IsPostBack)
    {
    if(1!=1)
    {
    //用户没有登陆
    }
    else
    {
    if(!Object.Equals(Request.QueryString["id"],null))
    {
      BookId=int.Parse(Request.QueryString["id"].ToString());
    if(Object.Equals(Request.Cookies["MyCart"],null))
    {
          cookie = new HttpCookie("MyCart");
      Response.Write("<script>alert('"+"开始新建Cookie"+"');</script>");
    }
    else
    .......

       
    }
    }
    }