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

[Solved] Remove a column in a child table

3 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Polaris431
Top achievements
Rank 1
Polaris431 asked on 15 Feb 2010, 05:14 PM
I would like to remove a column in a child table. The column to be removed depends upon the value of a certain column in the parent table. I have seen postings that show how to remove a column in the OnPreRender event but all those examples show how to remove a column in the MasterTableView. I need to remove the column in the child table.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Feb 2010, 06:56 AM
Hi,

Try the code snippet below to  hide the columns in the child table based on a value in the MasterTable:

ASPX:
 <MasterTableView Name="MasterTable" DataSourceID="AccessDataSource1" DataKeyNames="CustomerID" Width="100%" CommandItemDisplay="Top"

C#:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
            if (item.OwnerTableView.Name == "MasterTableName"
            { 
                if (item["CustomerID"].Text == "ALFKI"
                { 
                    GridTableView nestedTableView = (RadGrid1.MasterTableView.Items[item.ItemIndex] as GridDataItem).ChildItem.NestedTableViews[0]; 
                    nestedTableView.GetColumn("OrderID").Visible = false
                } 
            } 
        } 
    } 

For more information on  how to traverse  through hierarchy :
Traversing detail tables/items in Telerik RadGrid

Hope this helps.

Thanks,
Princy
0
Polaris431
Top achievements
Rank 1
answered on 17 Feb 2010, 03:43 PM
Well it's sort of what I wanted. I should have added a few more pieces of information though. My child table is actually on the 4th descendent level from the root table and not the 2nd level as you have in your example. I then need to inspect the value of some column in the 2nd level and use that to determine whether the column is removed. But there is actually something I should have also mentioned. When I remove the column, the actual column that gets removed depends on what the value is on the 2nd level. For one particular value, a certain column is removed but for a different value a different column is removed. In the aspx file, both columns are defined and initially have their visibility set to true.

When I bind the datatable to the datasource for the 4th level, the datasource will contain only the column that will be visible. it does not contain the column that is to be removed. 
0
Yavor
Telerik team
answered on 22 Feb 2010, 06:33 AM
Hi,

Basically, the approach supplied earlier will be valid for any level of hierarchy. You can traverse the items, and the nested tables in the same manner. Additionally, to make sure that all levels are available initially, you can set HierarchyLoadMode to "client". In this manner, the complete control structure will be accessible on first load.
I hope this information helps.

Best wishes,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Polaris431
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Polaris431
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or