我在页面第一个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);
} }
{
//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);
} }
接下来就取值咯
比如:
Userid=Request.Cookies["guid]
/// <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(); }
}
Cookie不能保存对象,只能保存值 或者先把对象序列化 获取后在反序列 不过有大小的限制(4k)