This is a migrated thread and some comments may be shown as answers.

How to hide empty columns?

0 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 08 Dec 2020, 01:15 PM

Give a grid with multiple columns. How can I hide column that has no value?

I ve tryed  something like this :

protected void RG_Import_PreRender(object sender, EventArgs e)
{
    foreach (GridColumn col in RG_Import.Columns)
    {
        bool valueFound = false;
        foreach (var row in RG_Import.Rows)
        {
            var cell = row.Cells[col.Name].Value;
            if (cell != null && cell != DBNull.Value && !string.IsNullOrWhiteSpace(cell))
            {
                valueFound = true;
                break;
            }
        }
        col.Visible = valueFound;
    }
}

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Share this question
or