单击整行的任何部分,触发网格视图的选定索引更改事件

时间:2011-12-14 10:59:01

标签: javascript asp.net gridview

我想在单击整行的任何部分时触发网格视图的选定索引更改事件

就像我不想显示一个select命令而不是用户可以点击一行的任何部分意味着一行的任何一列而该行被选中

感谢任何帮助

1 个答案:

答案 0 :(得分:5)

你没有提供语言,所以我将在VB.NET中展示一个例子(易于转换为C#):

以下列方式处理GridView的RowCreated事件:

Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
    Select Case e.Row.RowType
        Case DataControlRowType.DataRow
            e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';this.style.textDecoration='underline';"
            e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';"
            e.Row.ToolTip = "Click to select row"
            e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(DirectCast(sender,GridView), "Select$" & e.Row.RowIndex)
    End Select
End Sub

重要的一点是:

e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(DirectCast(sender, GridView), "Select$" & e.Row.RowIndex)

C#

e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink((GridView)sender, "Select$" + e.Row.RowIndex) 
相关问题