Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a GridView column by name at runtime in ASP.Net

Is it possible to show/hide a GridView column at runtime by name?

I can do it via the index like the following:

gridReviews.Columns[4].Visible = false;

However I'd like to do the following:

gridReviews.Columns["Name"].Visible = false;

What's the best way to do this?

like image 247
Sun Avatar asked Jun 13 '12 09:06

Sun


People also ask

How to hide column name in GridView in ASP net?

Columns["Name"]. Visible = false; What's the best way to do this? Are you wanting to use the header text or the column/property name in the underlying data source?

How do I hide a column in grid view?

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.


1 Answers

You can use the following code for it:

foreach (DataControlField col in gridReviews.Columns)
        {
            if (col.HeaderText == "Name")
            {
                col.Visible = false;
            }
        }
like image 59
Imran Balouch Avatar answered Sep 28 '22 22:09

Imran Balouch