Method to Find GridView Column Index by Name

前端 未结 7 2110
萌比男神i
萌比男神i 2020-12-09 04:00

I\'m trying to write a small method to loop through and find a GridView Column by its Index, since it can change position based on what might be visible.

<
7条回答
  •  被撕碎了的回忆
    2020-12-09 04:36

    Here's a VB version

    Protected Function GetColumnIndexByHeaderText(grid As GridView, findHeader As String) As Integer
        Dim i As Integer = 0
        For i = 0 To grid.Columns.Count - 1
            If grid.Columns(i).HeaderText.ToLower().Trim() = findHeader.ToLower().Trim() Then
                Return i
            End If
        Next
    
        Return -1
    End Function
    

提交回复
热议问题