none
Setting GridView Column Header Text in code-behind. RRS feed

  • Question

  • I have a gridview control called MyDataGrid which is being populated from a SQL server database:

    Dim ThisDataSet As DataSet = getData("my_datasource", sql_command)
    MyDataGrid.DataSource = ThisDataSet.Tables("thisData").DefaultView
    MyDataGrid.DataBind()

    I want to customize the gridview display exclusively in the code-behind.  Styling is not an issue but I cannot for the life of me figure out how to change the column HeaderText without using the following code on my ASPX page:

    <Columns>
    <asp:BoundField DataField="dbColumn" HeaderText="Custom Text" />
    </Columns>

    Can someone please tell me how to do this via the code-behind?  Every example I have found uses the above method, or is geared towards the DataGrid control and does not work with GridView.

    Any help would be greatly appreciated.
    • Moved by Martin Xie - MSFT Wednesday, July 9, 2008 11:42 AM Redirect to ASP.NET forums
    Wednesday, July 2, 2008 6:51 PM

All replies