Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET : Hiding columns in gridview

Is there a way I can control columns from code.

I had a drop drop box with select : Daily and weekend and the gridview column with Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,sunday. If the user selects Daily i want to show columns only from Monday to Friday.

It is possible to control from the code. Oh i am using this griview in my webpage and coding in done using C#.

help!

like image 519
jbcedge Avatar asked Oct 14 '08 02:10

jbcedge


3 Answers

Use Columns property:

GridView1.Columns[5].Visible = false
GridView1.Columns[6].Visible = false
like image 165
Pavel Chuchuva Avatar answered Oct 18 '22 06:10

Pavel Chuchuva


All these code snippet only works when you have AutoGenerateColumns set to false. If you are using AutoGeneratedColumns then you have to loop each row and hide the appropiate cells.

Thank

like image 3
Shakeeb Ahmed Avatar answered Oct 18 '22 05:10

Shakeeb Ahmed


In the Item DataBound event handler sub, for every grid row, check the drop list for "Daily" or "weekend" and then set the visibility of the columns in question to False or true where appropriate.

like image 1
Stephen Wrighton Avatar answered Oct 18 '22 05:10

Stephen Wrighton