How to hide columns in an ASP.NET GridView with auto-generated columns?

Try putting the e.Row.Cells[0].Visible = false; inside the RowCreated event of your grid.

protected void bla_RowCreated(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].Visible = false; // hides the first column
}

This way it auto-hides the whole column.

You don’t have access to the generated columns through grid.Columns[i] in your gridview’s DataBound event.

Leave a Comment