我目前在ASP.Net / C#工作。我试图通过数据网格中的行使服务器重定向到另一个页面,但是,我的代码似乎没有 上班。任何帮助,将不胜感激。
protected void GridView1_RowCreated()
{
foreach (GridViewRow row in GridView1.Rows)
{
Color color = row.BackColor;
string color2 = System.Drawing.ColorTranslator.ToHtml(color);
Session["" + row.Cells[0].Text + ""] = row.Cells[0].Text;
//row.Attributes.Add("onclick", "zz(); return false;");
/*if (row.RowState == DataControlRowState.Alternate)
{
row.Attributes.Add("onclick", "redirectFunction(); return false;");
//row.Attributes.Add("onmouseover", "this.style.backgroundColor=' #FFFFFF';");
//row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + color2 + "';");
//row.Attributes.Add("onclick", cookie.Value = row. GridView1.SelectedRow.Cells[0].Text);
//row.Attributes.Add("onclick", "zz(); return false;");
}
else
{
//row.Attributes.Add("onmouseover", "this.style.backgroundColor=' #FFFFFF';");
//row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + color2 + "';");
//row.Attributes.Add("onclick", "zz(); return false;");
}*/
}
}
public void redirectFunction()
{
Response.RedirectPermanent("View.aspx");
}
Other page
if(Session["session"].ToString() != null)
{
// do something
}
答案 0 :(得分:0)
您应该使用GridView的SelectedIndexChanged事件来实现此功能。从那里,您可以获取需要在View.aspx页面中显示的对象的所有属性和信息。
答案 1 :(得分:0)
在这里查看这篇文章,这将帮助您实现您的目标 https://stackoverflow.com/a/331662/125551
只需添加session [“var”] = val或在url中发送该值,并在querystring而不是session
的其他页面上的page_load中获取该值