'Hide gridview column header

I have a gridview that is populated from a sqldatasource with ajax, which is fired from a radcombox drop down. The below does not work because technically the gridview hasn't loaded. Is there an easy work around?

Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
    GridView1.HeaderRow.Cells(1).Visible = False
End Sub


Solution 1:[1]

<asp:GridView ID="GridView1" runat="server" ShowHeader="False">
        </asp:GridView>

showheader=false on the aspx page

Solution 2:[2]

Just hide the cell after the entire GridView is bound in the DataBound event:

Protected Sub GridView1_DataBound(sender As Object, e As EventArgs)  
    GridView1.HeaderRow.Cells(1).Visible = False
End Sub

<asp:GridView ID="GridView1" runat="server" OnDataBound="GridView1_DataBound">

Just know that this only hides the contents of the header cell, not the entire column.

Solution 3:[3]

Write code line after Data Bind method or after binding grid on Page Load method

   GridView1.DataBind();
   if (GridView1.Rows.Count > 0)// check if grid not empty
      {
            GridView1.HeaderRow.Cells[1].Visible = false;//hide grid column header
            GridView1.Columns[1].Visible = false;//hide grid column value
      }

Solution 4:[4]

GridView1.HeaderRow.Cells[1].Visible = false;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3786581
Solution 2 j.f.
Solution 3 hussains8
Solution 4 user18878610