I have following code to hide column and edit column header. But its not going into foreach. I have tried various method by putting the foreach into DataBound, RowDataBound, RowCreated events. But not working.
GridView1.AutoGenerateColumns = true;
GridView1.DataSource = SomeObject[];
GridView1.DataBind();
foreach (DataControlField col in GridView1.Columns)
{
if (col.HeaderText == "FirstName")
{
col.HeaderText = "First Name";
}
if (col.HeaderText == "SchoolName")
{
col.Visible = false;
}
}
Can anyone please advice me the fix. Thanks