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

[Solved] Getting a Gridcolumn in a RadGrid to be hidden

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Corey
Top achievements
Rank 1
Corey asked on 11 Jun 2009, 02:36 PM
Hello everyone,

Here is what i am trying to do.

I am trying to hide a Gridcolumn in a RadGrid.

I have found the code to do it... i just don't seem to get it to fire when i am first loading the Grid.

Here is my setup

Radtabstrip (6 tabs) with RadMultipage with 6 RadPageviews
each tab(views) has a RadGrid in it.  Each one of the grids has a maximum amount of columns that can be displayed and i have a check box control that limits what is displayed.

I have the code that iterates through the checkboxlist and hides the columns... I just cannot get this code to fire when the page first loads...

Where should i be putting this code in (right now it is in the checkboxlist selecteditem changed event... which is good ... but i also need this filtering done on first page load.

Thanks for any ideas...

Corey

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2009, 11:54 AM
Hello Corey,

You can check out the following code and see if it suits your requirement:
aspx:
<telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1" SelectedIndex="0"
                <Tabs> 
                    <telerik:RadTab runat="server" Text="Tab1" PageViewID="PageView1"
                    </telerik:RadTab> 
                    <telerik:RadTab runat="server" Text="Tab2" PageViewID="PageView2"
                    </telerik:RadTab> 
                </Tabs> 
            </telerik:RadTabStrip> 
            <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false"
                <telerik:RadPageView runat="server" ID="PageView1"
                    <asp:CheckBoxList ID="CheckBoxList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"
                        <asp:ListItem Text="CompanyName" Value="CompanyName"></asp:ListItem> 
                        <asp:ListItem Text="ContactName" Value="ContactName"></asp:ListItem> 
                        
                    </asp:CheckBoxList> 
                    <telerik:RadGrid ID="RadGrid1" AllowPaging="true" PageSize="5" 
                        DataSourceID="SqlDataSource1" AutoGenerateColumns="true" runat="server" OnPreRender="RadGrid1_PreRender" > 
                        <MasterTableView> 
                          ..  
                        </MasterTableView> 
                    </telerik:RadGrid></telerik:RadPageView> 
                <telerik:RadPageView ID="PageView2" runat="server"
                  .... 
                </telerik:RadPageView> 
            </telerik:RadMultiPage> 

c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (ListItem item in CheckBoxList1.Items) 
        { 
            if (!item.Selected) 
                RadGrid1.MasterTableView.GetColumn(item.Value).Visible = false
        } 
    } 
 
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        foreach (ListItem item in CheckBoxList1.Items) 
        { 
            if (item.Selected) 
            { 
                RadGrid1.MasterTableView.GetColumn(item.Value).Visible = true
                RadGrid1.Rebind(); 
            } 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Corey
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or