ASP.NET: hiding columns in gridview

Is there a way to manage columns from code.

I had a drop drop with a choice: daily and weekends and a gridview column from Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. If the user selects Daily, I want to show columns only Monday through Friday.

The code can be controlled. Oh, I use this griview on my webpage and code using C #.

help!

+6
gridview
source share
5 answers

Use the Columns property:

GridView1.Columns[5].Visible = false GridView1.Columns[6].Visible = false 
+8
source share

All these code snippets only work when AutoGenerateColumns is set to false. If you use AutoGeneratedColumns, you need to loop each row and hide the corresponding cells.

thanks

+3
source share

In the Item DataBound event handler element for each grid row, check the drop-down list for Daily or Weekend, and then set the visibility of the columns in question to False or true, if necessary.

+1
source share

You can programmatically hide or show columns by indexing in Columns and setting the Visible property.

For example, to hide the first column in your gridview:

 theGridview.Columns[0].Visible = false; 
+1
source share

It may be convenient for you to use the column index - the Columns property also accepts the column name that you can set when creating using the Name property of this column. This helps make code self-declaration.

0
source share

All Articles