Any way to manipulate the columns in GridView with AutoGenerateColumns = true?

前端 未结 5 457
谎友^
谎友^ 2020-12-11 17:42

It seems like there\'s no way to manipulate the columns of a Gridview if AutoGenerateColumns = true. Here\'s my scenario:

I\'ve got a generic GridView that displays

5条回答
  •  醉梦人生
    2020-12-11 17:54

    You can manipulate things on data bound like this:

    Private Sub MyGrid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Me.RowDataBound
      If Me.AutoGenerateColumns = True Then
        If e.Row.RowType = DataControlRowType.DataRow Then
              e.row.cells.add(some code here to add your special column)
        End If
        End If
    End Sub
    

    You'd have to create your own header to but it's very doable.

提交回复
热议问题