Change GridView column headings

I have a simple web app that calls a function to fill a DataTable.  I cannot control the GetData routine.  However, I take the results and bind it to a GridView at runtime.

Is there a way to change the column heading text on the GridView?  I have tried a few things but nothing seems to work.

Below is my code.  When I run it, the column headings for the GridView are "Field1", "Field2", and 'Field3".  Can I instead write code to change these to something else?  How?  Remember that I can't control the GetData routine.  

Thanks,
Chris


Partial Public Class _Default
    Inherits System.Web.UI.Page

    Shared dt As DataTable

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            dt = GetData()
            GridView1.DataSource = dt
            GridView1.DataBind()
            'GridView1.Columns(0).HeaderText = "New Text"     '<----- something like this
        End If

    End Sub
 
    'Private Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
    '    GridView1.Columns(0).HeaderText = "New Text"
    'End Sub

    Protected Function GetData() As DataTable

        Dim dt As New DataTable

        dt.Columns.Add("Field1")
        dt.Columns.Add("Field2")
        dt.Columns.Add("Field3")

        Dim drow As DataRow

        drow = dt.NewRow
        drow("Field1") = "Test1"
        drow("Field2") = Now.ToString("MM/dd/yyyy HH:mm:ss")
        drow("Field3") = "id"
        dt.Rows.Add(drow)

        drow = dt.NewRow
        drow("Field1") = "Test2"
        drow("Field2") = Now.ToString("MM/dd/yyyy HH:mm:ss")
        drow("Field3") = "id"
        dt.Rows.Add(drow)

        Return dt

    End Function

End Class
chladeAsked:
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.

FlorinAntociCommented:
simple,
  dt = GetData()
           
//here change the columns name in the dt variable, before binding, like:
 dt.Columns[0].Caption = "what do you want"; etc if caption does not work, try column name
           GridView1.DataSource = dt
            GridView1.DataBind()

Regards
0

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.