在cookie中存储多个值

时间:2011-09-12 09:40:42

标签: asp.net asp.net-ajax

我想在一个cookie中存储多个值..但它无法使用Plus名称创建新密钥。在创建Plus键之后,我想在Plus中保存值,然后检索它们。

 protected void GVLinks_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Plus")
        {
            string ID = e.CommandArgument.ToString();

            HttpCookie Pluscoc = Request.Cookies["Plus"];

            if (Request.Cookies["Plus"] == null)
            {
                Pluscoc = new HttpCookie("Plus");
            }

            if (Request.Cookies["Plus"][ID] == null)
            {
                SqlConnection scn = new SqlConnection(ClassPublic.GetConnectionString());
                SqlCommand scm = new SqlCommand("UPDATE tblLinks SET Rate = Rate+1 WHERE ID=@ID", scn);
                scm.Parameters.AddWithValue("@ID", e.CommandArgument);
                scn.Open();
                scm.ExecuteNonQuery();
                scn.Close();

                BindMydata();
                GetRetDate();

                Pluscoc.Values.Add(ID, ID);
            }
        }
    }

0 个答案:

没有答案