C# 如何使用DataKey从网格视图重定向
我希望网格视图在单击某一行时重定向,因此我为网格视图创建了onrow,但无法重定向到所需的页面C# 如何使用DataKey从网格视图重定向,c#,asp.net,gridview,datagrid,databound,C#,Asp.net,Gridview,Datagrid,Databound,我希望网格视图在单击某一行时重定向,因此我为网格视图创建了onrow,但无法重定向到所需的页面 <asp:GridView ID="Grid_Messagetable" runat="server" OnRowCreated="Grid_Messagetable_RowCreated" AllowPaging="False" SelectedIndex="0" DataKeyNames="MsgID" ShowHeaderWhenEmpty="true"
<asp:GridView ID="Grid_Messagetable" runat="server" OnRowCreated="Grid_Messagetable_RowCreated" AllowPaging="False" SelectedIndex="0"
DataKeyNames="MsgID" ShowHeaderWhenEmpty="true"
OnRowDataBound="MyGrid_RowDataBound" AutoGenerateColumns="False" AllowSorting="true"
OnSorting="gridView_Sorting" Height="16px" Width="647px"> protected void Grid_Messagetable_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onClick", "this.style.background='#eeff00'");
}
我试过这个
e.Row.Attributes["onClick"] = "location.href=
'ResponseMetric.aspx?MsgID=" + DataBinder.Eval(e.Row.DataItem, "MsgID") + "'";
但我得到了下面的错误
Uncaught ReferenceError: redirect is not defined
(anonymous function)Messages.aspx:774
onclick
如果需要,可以打开新窗口并关闭现有窗口。试试这个e.Row.Attributes.Add(“onClick”,“javascript:window.open('ResponseMetric.aspx?MsgID=“+your value+”)”)。简单的修复方法,只需更改您的
RowDataBound
方法,我可以看到您已经实现了该方法,以包括以下代码片段:
protected void MyGrid_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onClick"] = string.Format(
"window.location = 'ResponseMetric.aspx?MsgID={0}';",
DataBinder.Eval(e.Row.DataItem, "MsgID"));
}
}
下面是谷歌的一个基本工作示例:
protected void grdTest_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onClick"] =
"window.location = 'http://www.google.com/';";
}
}
在gridview中单击某行或某行中的任何特定控件时,是否可以发布gridviewr u重定向的标记?这可能会帮助您@Kathi,当用户单击该行中的任何位置时,我希望重定向
protected void grdTest_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onClick"] =
"window.location = 'http://www.google.com/';";
}
}