Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net change header text of GridView template columns

Hi.  I am trying to change the header text of template columns in a GridView in ASP.net using the following VB.net code but for some reason the
headers are not changing

    Private Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        For i As Integer = 0 To UBound(arrDates)
            oColIndex = i + 2
            oTemplateColumn = "D" & CStr(i + 1)
            oEachDate = CDate(arrDates(i))
            oDate = oEachDate.ToString("dd MMM yyyy")
            Me.GridView1.Columns(oColIndex).Visible = True
            If e.Row.RowType = DataControlRowType.Header Then
                Me.GridView1.Columns(oColIndex).HeaderText = oDate
            End If
        End if
Ebd Sub

Open in new window

Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

but for some reason the
headers are changing
-- Not sure what this means.

You do not need to write this code inside gridview rowdatabound. You can write it after your code to gridview1.DataBind();
For i As Integer = 0 To UBound(arrDates)
            oColIndex = i + 2
            oTemplateColumn = "D" & CStr(i + 1)
            oEachDate = CDate(arrDates(i))
            oDate = oEachDate.ToString("dd MMM yyyy")
            Me.GridView1.Columns(oColIndex).Visible = True
            Me.GridView1.Columns(oColIndex).HeaderText = oDate
        End if

Open in new window

Avatar of Murray Brown

ASKER

sorry missed the word "not"
ASKER CERTIFIED SOLUTION
Avatar of Murray Brown
Murray Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial