日期:2014-05-18  浏览次数:20840 次

gridview中linkbutton的使用
我这里有个gridview,最后一列是一个button列,点击button的时候打开一个新的窗口,我现在想点击button的时候获得某一行中的两个值,用session传递到新开的页面,请教该如何实现?谢谢!

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  {
  string jinghao1;
  jinghao1 = e.CommandArgument.ToString();
  Session["shjh"] = jinghao1;
  //这里,除了jinghao之外,我还想获得jcsj字段的值一并传到新开的页面中。。。。。。  
  Response.Write("<script language='javascript' type='text/javascript'>window.open(\"shenhepage.aspx\");</script>");
  }

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  LinkButton Button1 = (LinkButton)e.Row.Cells[6].Controls[0];
  Button1.CommandArgument = e.Row.Cells[2].Text;

  }
  }

------解决方案--------------------
劝你还是用Url传吧。

------解决方案--------------------
最好使用查询字符串的方式传递,不是所有的数据都适合用Session

而且楼主最好贴贴页面代码
------解决方案--------------------
楼主这段代码出了什么问题?
------解决方案--------------------
楼主如果真要是使用session传值的话
把gridview的button事件改成GridView1_RowUpdateing()
protected void GridView1_RowUpdateing(object sender, GridViewRowEventArgs e) 

string 1=this.GridView1.Rows[e.RowIndex].Cells[b].text;
//b就是你想要取的值,可以取多个
Session["shjh"] = 1;
Response.Redirect("新的页面");
}
这样做就可以