Hide GridView column

  • Thread starter Thread starter DavidC
  • Start date Start date
D

DavidC

I have a GridView that I want to hide a whole column based on a condition
known before it is Databound. Is the best place to do this in RowDatabound
or in PreRender or ??? Thanks.
 
I have a GridView that I want to hide a whole column based on a condition
known before it is Databound. Is the best place to do this in
RowDatabound
or in PreRender or ??? Thanks.

I wouldn't do either...

Presumably you have a server-side method which does the databinding and
which you call as and when required e.g.

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindData();
}
}

private void BindData()
{
DataSet MyDS = <fetch a DataSet from the DAL/BOL>;
MyGridView.DataSource = MyDS;
MyGridView.DataBind();
MyGridView.Columns[3].Visible = false; // hide the column
}
 
Back
Top