我目前在ASP.Net/C#中工作。我試圖通過數據網格中的行使服務器重定向到另一個頁面,但是,我的代碼看起來並不是 。任何幫助,將不勝感激。通過datagridView重定向
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
}
只是從gridview的selectedIndexChanged調用javascript函數什麼也不做。 – MasterP
我已經更新了上面的代碼。如果你仍然陷入困境,你能否提供更多信息。 – Renae
另外,SelectedIndexChanged將在選中該行時觸發,而不是單擊。 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onselectedindexchanged.aspx – Renae