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

[Solved] Hide unused columns

2 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carsten Højgaard
Top achievements
Rank 1
Carsten Højgaard asked on 16 May 2008, 09:45 AM
I’m looking for a way to hide columns in the RadGrid that does not contain any data.

Anyone got an idea on how to do this without iterating the whole grid?

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 May 2008, 10:42 AM
Hi,

Try the following code snippet to loop through each item in the Grid.

CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
        {  
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)  
            {  
                string strtxt = item[col.UniqueName].Text.ToString();  
                if (strtxt == " ")  
                {  
                    item[col.UniqueName].Visible = false;  
                }  
            }  
        }  
    } 


Thanks
Princy.
0
Carsten Højgaard
Top achievements
Rank 1
answered on 16 May 2008, 01:04 PM

Hi Princy

Thank you for your quick reply… and of cause the code ;)
It works perfectly. To hide the column, I had to change:

item[col.UniqueName].Visible = false

 
to

col.Display = false


Thanks again!
Carsten

 

Tags
Grid
Asked by
Carsten Højgaard
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Carsten Højgaard
Top achievements
Rank 1
Share this question
or