Menu Horisontal

Jumat, 27 April 2012

How to hide Gridview column programmatically?


Solution : From  http://asmaqureshi.blogspot.com/2011/09/how-to-hide-gridview-column.html

The Columns collection only stores the explicitly declared columns, so if you’re using autogenerated columns, the count will be zero.
If you’re using autogenerated column, after databind you could loop through the rows collection and make the appropriate cells invisible, like:

 GridView1.DataBind();
 if (GridView1.Columns.Count > 0)
 GridView1.Columns[0].Visible = false;
   else
  {
     GridView1.HeaderRow.Cells[0].Visible = false;
     foreach (GridViewRow gvr in GridView1.Rows)
  {
   gvr.Cells[0].Visible = false;
  }
 }

Tidak ada komentar: