yahoo invisible

Thursday, April 16, 2009

A simple but important difference of datagrid and gridview (asp.net 2.0 vs earlier)

asp.net earlier (ex:Visual studio .net 2003)
datagrid control binds data before hiding columns

but in asp.net 2.0 (VS 2005)
gridview first hide the columns and then bind data.

So if you set some column visible=false at design time those columns will have null values.

Solution: Hide the columns at run time in grid view's row created event.

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[1].Visible = false; //columns you want to hide
e.Row.Cells[2].Visible = false;
}