[英]How to make entire Gridview Row clickable and open a new link?
如何在ASP.NET中使整个gridview行可单击?
这是我目前正在尝试的方法:
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onclick", "location.href='URL.aspx'")
End If
End Sub
每行包含多个模板字段,因此在这种情况下,仅向该字段添加超链接是不够的。
VB
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gv.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim QueryString As String = DataBinder.Eval(e.Row.DataItem, "QueryString").ToString
Dim NavigateURL As String = (ResolveUrl("~/URL.aspx?QueryString=" + QueryString))
e.Row.Attributes.Add("onClick", String.Format("javascript:window.location='{0}';", NavigateURL))
e.Row.Style.Add("cursor", "pointer")
End If
End Sub
C#
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) {
if ((e.Row.RowType == DataControlRowType.DataRow)) {
string QueryString = DataBinder.Eval(e.Row.DataItem, "QueryString").ToString;
string NavigateURL = ResolveUrl(("~/URL.aspx?QueryString=" + QueryString));
e.Row.Attributes.Add("onClick", string.Format("javascript:window.location=\'{0}\';", NavigateURL));
e.Row.Style.Add("cursor", "pointer");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.