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

[Solved] How to hide columns in a grid but show them during edit

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan Donahue
Top achievements
Rank 1
Ryan Donahue asked on 03 Sep 2009, 02:26 PM
My working environment is VS 2008, .Net 3.5, and RadControls for ASP .NET Q3 2007.

I have a grid displaying on my page.  each record has 30 columns.  I want the user to be able to edit these values in the edit popup box but I obviously don't want to try to display the grid w/ all 30 columns.  Right now I am setting the visibility of the columns in the PreRender which hides the unwanted columns when the grid is not in edit mode and shows all the columns in the edit popup.  Unfortunately, this also shows all the columns in the grid behind the edit window.  Is there someway to specifiy that I only want to change the visibility of the edit windows columns instead of the MasterTableView?

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 04 Sep 2009, 03:17 PM
Hello Ryan,

I would suggest you set the visibility of the columns using the ColumnCreated event handler:

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (e.Column.UniqueName == "MyColumnName"
        { 
            e.Column.Visible = false
        } 
    } 


Please note that this approach works for auto-generated columns only. For declarative grid columns you can use the PreRender event handler:

 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridColumn column in RadGrid1.Columns) 
        { 
            if (column.UniqueName == "MyColumnName"
            { 
                (column as GridColumn).Visible = false
                break
            } 
        } 
        RadGrid1.Rebind(); 
    } 


You can review this help topic for more details on how to customize the columns programmatically.

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Ryan Donahue
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or