【发布时间】:2015-09-13 22:39:58
【问题描述】:
我在会话中存储 gridview 行的主键值并将其显示在另一个网页上我正在尝试下面的代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Migrate")
{
int _rowindex = Convert.ToInt32(e.CommandArgument);
GridViewRow _selectedrow = GridView1.Rows[_rowindex];
TableCell _firstcell = _selectedrow.Cells[0];
Session["authId"] = _firstcell.Text + "";
Response.Redirect("WebForm2.aspx");
}
}
通常代码工作正常,但_firstcell 值在将我的页面重定向到 webform2 后未存储在会话中,它运行其他条件。我正在使用 webform2 的以下代码 onpageload:
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Session["authId"].ToString()))
Response.Write(Session["authId"].ToString());
else
{
Response.Write("Empty Session");
}
}
【问题讨论】:
-
在您的gridview rowcommand 中放置一个断点并检查_firstcell.Text 的值。它有价值吗?
-
您是否尝试过在一个页面上设置另一个会话变量,然后在另一个页面上读取它?这样您就可以验证它是一般问题还是特定问题。
-
是的,我放了断点,它告诉我 _firstcell 变量中没有显示值,所以我进一步处理我的代码并获取 gridview 行的主键。我在我自己的答案下面发布了我更改了一行代码以获得我想要的答案。