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

Murray BrownHead DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Obadiah ChristopherDeveloper User InterfaceCommented:
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

Murray BrownHead DeveloperAuthor Commented:
sorry missed the word "not"
Murray BrownHead DeveloperAuthor Commented:
This worked for me in the RowDataBound event
  If e.Row.RowType = DataControlRowType.Header Then
                    e.Row.Cells(oColIndex).Text = oDateForHeader
   End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.