简体   繁体   English

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

[英]Fire a selected Index change event of a grid view on clicking any portion of a whole row

I want to Fire a selected Index change event of a grid view on clicking any portion of a whole row 我想在单击整行的任何部分时触发网格视图的选定索引更改事件

It s like i dont want to show a select command rather than user can click any portion of a row means any column of a row and that row get selected 就像我不想显示选择命令,而不是用户可以单击一行的任何部分意味着一行的任何列都可以被选中

ANy help is appreciated 感谢您的帮助

You don't have provided the language, so i will show you an example in VB.NET(easy to convert to C#): 您没有提供语言,所以我将在VB.NET中向您展示一个示例(易于转换为C#):

Handle the RowCreated event of the GridView in the following way: 通过以下方式处理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

The important line is: 重要的一行是:

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

C# C#

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM