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?
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?
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.
You can use the following code for it:
foreach (DataControlField col in gridReviews.Columns)
{
if (col.HeaderText == "Name")
{
col.Visible = false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With