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

Hide Columns when Using NeedDataSource

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nate
Top achievements
Rank 1
Nate asked on 26 Jul 2010, 10:35 PM
Hi, I am trying to hide columns when using NeedDataSource.  Right now I am hiding them in the column created event, as I have a database table of columns that are visible/invisible.  When I use a control that changes the column visibility and postback the grid using rebind() it is not hiding the columns, even though my code is doing the right thing.
I am pulling my hair out on this.  Is there a better solution rather than using the column created event?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jul 2010, 06:52 AM
Hello,


Have you tried to hide the columns in PreRender event of RadGrid?

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
    {
        if (column.UniqueName == "ID")
        {
            column.Visible = false;
        }
    }
    RadGrid1.Rebind();
}



-Shinu.
0
Nate
Top achievements
Rank 1
answered on 27 Jul 2010, 06:54 PM
I tried your method as well.  However, since I'm using different datasources for the grid, the columns weren't populated at that point.
I ended up having to turn autogeneratecolumns = false, and then programmatically adding the columns to the grid.
Thanks for your help!
Tags
Grid
Asked by
Nate
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Nate
Top achievements
Rank 1
Share this question
or