我在页面第一个girdview上面放一个加入收藏栏的imagebutton按钮,要求是我点击这一列的按钮就要把这一列的信息传个同一个页面的另外一个girdview控件(但实际上是放在模板页里面)上显示,要求用cookie 做。 这是我在第一个 gridview控件  创建的cookie。 不知道有没有错,然后在另外一个girdview里面不知道怎么写。请大侠帮帮忙~~     protected void GVInternshipNews_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            //{ 
            //e.Row.Cells[6].Visible=false;
            //}            if (e.Row.RowType==DataControlRowType.DataRow)
            {
                string intobar = this.GVInternshipNews.DataKeys[e.Row.RowIndex]["Guid"].ToString();
                ImageButton imagebtnInto = e.Row.Cells[0].FindControl("ImageButtonIntoBar") as ImageButton;
                HttpCookie cookie = new HttpCookie("guid"); //创建一个cookie
                //上一次访问时间
                cookie.Value = DateTime.Now.ToString();
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);
             
            }        }

解决方案 »

  1.   

    既然存好了 
    接下来就取值咯
    比如:
    Userid=Request.Cookies["guid]
      

  2.   

    我在另外一个gridview里面是通过createtable来的,
            /// <summary>
            /// 创建一个临时表
            /// </summary>
            private void CreateTable()
            {            DataTable dt = new DataTable();
                dt.Columns.Add(new DataColumn("Guid"));
                dt.Columns.Add(new DataColumn("JobName"));
                dt.Columns.Add(new DataColumn("Location"));
                DataRow dr = dt.NewRow();
                dr["Guid"] =JobGuid;
                dr["JobName"] = position.Jobname;
                dr["Location"] = position.Location;
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["Guid"] = JobGuid;
                dr["JobName"] = inter.Jobname;
                dr["Location"] = inter.Location;
                dr = dt.NewRow();
                dr["Guid"] = JobGuid;
                dr["JobName"] = train.CourceName;
                dr["Location"] = train.Lacation;
                ViewState["position"] = dt;
                BindTempData();         }
    不知道我下面这样子写怎么得不到值呢???   /// <summary>
            /// 获取cookie的值
            /// </summary>
            public void GetInternship()
            {
                if (Request.Cookies["guid"] != null)
                {                HttpCookie aCookie = Request.Cookies["guid"];                this.GVJobCar.DataSource= Server.HtmlEncode(aCookie.Value);
                    this.GVJobCar.DataBind();            }         
            
            }
      

  3.   

    我要把原来gridview的那一行值,怎么用cookie 传过去,在另外一个gridview中去出来啊??
      

  4.   

    aCookie.Value是值不是数据源,使用session保存datatable等
      

  5.   

    顶  
    Cookie不能保存对象,只能保存值   或者先把对象序列化  获取后在反序列  不过有大小的限制(4k)
      

  6.   

    我觉得方向是不对的,你要的效果考虑一下,GridView的RowCommand事件,它能帮你解决这些的,本质是ViewState中的值。