SIGN UP MEMBER LOGIN:    
Blog

How To: Hiding a Column in a DataBound GridView

Posted by Mike Gold Blogs | ASP.NET Programming Aug 01, 2007
As obvious as you would think this would be, it turns out that in order to hide column in a GridView, you need to go through a pretty unintuitive step. (The Windows Form Version is much more flexible). Here I'll show you how.

How do you hide a column for a DataBound GridView

I found this solution on http://www.beansoftware.com/ASP.NET-Tutorials/GridView-Hidden-Column.aspx  and it was not as easy to find as you would think.  I saw people suggesting the obvious like set the Visible property of the Column to false or  (the less obvious)  set the width of the column to 0.  None of these work for a DataBound GridView.

The way to hide a column in a DataBound GridView is to trap the RowCreated Event and set a Cell inside the column of the row to Visible = false. Nice!

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{

//  hide a cell in the column to hide column 1
 
e.Row.Cells[1].Visible = false;
}

share this blog :
post comment
 

private void rgdCDR_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e) {rgdCDR.Columns[9].IsVisible = true;rgdCDR.Columns[10].IsVisible = true;rgdCDR.Columns[11].IsVisible = false;}

Posted by Sajjad Ahmed Apr 27, 2012

in order to set visible property of grid row or column you have to use template field not auto generated columns and by using template field you can make its visibility to false

Posted by Harshit Vyas Nov 09, 2010

Is it possible to hide the columns using checkboxes...?? suppose we have 9 columns and we want to hide the selected columns using checkboxes at run time.. using a context menu......if it is possible plzz send me the code at rahulrannot@gmail.com lotz of thanks in advance...

iam using jquery Context menu plugin to show a context menu having a list of checkboxes..

Posted by rahul rannot Nov 08, 2010

 Is it possible to hide the columns using checkboxes...?? suppose we have 9 columns and we want to hide the selected columns using checkboxes at run time.. using a context menu......if it is possible plzz send me the code at rahulrannot@gmail.com lotz of thanks in advance...

Posted by rahul rannot Nov 08, 2010

Hey Mike Thanks for the information

Posted by Sandeep Pathania Nov 08, 2010