【发布时间】:2012-01-05 14:29:52
【问题描述】:
我希望网格视图在单击一行时重定向,所以我为网格视图创建了 OnRowCreated,但我无法重定向到我想要的页面
<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'");
}
在这里,我尝试在单击一行时设置背景颜色并且它有效,但是我如何重定向页面,我必须使用 msgID 重定向到 ResponseMetrci.aspx 页面,就像我在下面所做的那样。所以我在 url 中传递了 msgid,以便在响应指标页面中检索它。
Eval("MsgID", "ResponseMetric.aspx?MsgID={0}") %>'
我试过了
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
【问题讨论】:
-
你能发布你的gridview的标记
-
您是否在单击gridview中的一行或一行中的任何特定控件时重定向?
-
@Kathi,我想在用户点击行中的任意位置时重定向
标签: c# asp.net gridview datagrid databound