using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Class1 aas = new Class1();
            //     string id= Request.QueryString["id"];
            string id = "1";
            string str = "select * from member where id>@id";
            ;
            SqlConnection con = new SqlConnection("Data Source=ZH-B0140C4856DE;DataBase=ycw;User ID=sa;PWD=owen2000");
            con.Open();
            SqlDataAdapter ssd = new SqlDataAdapter(str, con);
            SqlParameter[] parms ={ aas.MakeInParam("@id", SqlDbType.BigInt, 50, id) };
            ssd.SelectCommand.CommandType = CommandType.Text;
            if (parms != null)
            {
                foreach (SqlParameter pp in parms)
                    ssd.SelectCommand.Parameters.Add(pp);            }
            DataSet ds = new DataSet();
            ssd.Fill(ds);
            DataList1.DataSource = ds.Tables[0].DefaultView;
            DataList1.DataKeyField = "id";
            DataList1.DataBind();
            con.Close();        }    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string[] userid ={ "dfd", "123" };         HttpCookie cookie = new HttpCookie("aspcn");
        if ("redirect".Equals(e.CommandName))
        {
            this.Label3.Text = "hahaha";            ImageButton ib = (ImageButton)e.Item.FindControl("ImageButton1");
            string id = ((Label)e.Item.FindControl("Label1")).Text;           
            cookie.Values.Add("id", id);
            cookie.Values.Add("userid", userid);            Response.AppendCookie(cookie);
            Response.Redirect("cookie.aspx?id="+id+"");
        }    }
}
错误 1 出处
 cookie.Values.Add("userid", userid); 中的cookie
错误1 
与“System.Collections.Specialized.NameValueCollection.Add(string, string)”最匹配的重载方法具有一些无效参数错误2出处
 cookie.Values.Add("userid", userid); 中的userid
错误 2 参数“2”: 无法从“string[]”转换为“string”
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class cookie : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.Cookies["aspcn"]["id"].ToString();            for (int j = 0; j < cookie.Count; j++)
            {                              Response.Write("子键名=" + Cookies["aspcn"]["userid"] + "<br/>");
            }
            this.Label1.Text = id;
        
        }
    }
}错误3出处    for (int j = 0; j < cookie.Count; j++) 中的 count
错误 3 “cookie”并不包含“Count”的定义
错误4   
错误 4 当前上下文中不存在名称“Cookies” 哪位高手帮我看看这几个错误怎么改 帮我把改的代码贴出来
谢谢

解决方案 »

  1.   

    //多值Cookie的写法 //方式1: 
    Response.Cookies["userinfo1"]["name"].value="1"; 
    Response.Cookies["userinfo1"]["last"].value="1"; 
    Response.Cookies["userinfo1"].Expires=DateTime.MaxValue; //方式2: 
    HttpCookie cookie = new HttpCookie("userinfo1"); 
    cookie.Values["name"]="mike"; 
    cookie.Values["last"]="a"; 
    cookie.Expires=DateTime.MaxValue; 
    //cookie.Expires = System.DateTime.Now.AddDays(1); 
    Response.Cookies.Add(cookie); 
    //多值Cookie的读取 
    If ( Request.Cookies["userInfo1"]!=null ) 

      string name=Request.Cookies["userInfo1"]["name"]; 
      string last=Request.Cookies["userInfo1"]["last"]; 
    } 你参考一下吧
      

  2.   

    错误1、2:Add()方法的第二个参数应该是String,而不能是String[]
    http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection.add.aspx
    错误3:cookie被你定义为类名了,System.Web.UI.Page怎么还会有Count属性?
    错误4:从来没有见你定义过Cookies,怎么能调用?至于怎么改,你自己研究一下吧。
      

  3.   

    问题是我用购物车存储cookie数组 我哪里事先知道他是什么名字 我真晕啊
      

  4.   

    错误 1 出处 
    cookie.Values.Add("userid", userid); 中的cookie 
    错误1 
    与“System.Collections.Specialized.NameValueCollection.Add(string, string)”最匹配的重载方法具有一些无效参数 

    cookie.Values.Add(这里边是两个string的参数),而你的userid是一个string[]
    错误2出处 
    cookie.Values.Add("userid", userid); 中的userid 
    错误 2 参数“2”: 无法从“string[]”转换为“string”Add()方法中是两个string的参数,而你的userid是一个string[] 所以它会报无法从string[]转到string
      

  5.   

    错误3出处    for (int j = 0; j < cookie.Count; j++) 中的 count 
    错误 3 “cookie”并不包含“Count”的定义 
    错误4  
    错误 4 当前上下文中不存在名称“Cookies” 修改你的代码为:
    string id = Request.Cookies["aspcn"]["id"].ToString();             for (int j = 0; j < Request.Cookies.Count; j++) 
                {                               Response.Write("子键名=" + Request.Cookies["aspcn"]["userid"] + " <br/>"); 
                }