RadGrid for ASP.NET AJAX

RadControls for ASP.NET AJAX

Accessing the DetailTables through NestedTableViews Collection

If you have a hierarchical grid each item in GridTableView'sItems collection has a child item of type GridNestedViewItem that has a set of DetailTables. So if you want to access, for example, the nested table view of the first item in the grid's master table you should have the following code:

Or if you have a reference to an instance of an item in a child table and if you want to access the parent item/parent table view you have to write the following code:

Looping through all detail tables/items in Telerik RadGrid

Before proceeding with the rest of this chapter we recommend you reading the KB article of Telerik RadGrid concerning Hierarchical binding tips. After reading the article, you will understand that each copy of a detail table corresponding to an item from the parent table resides in a NestedViewItem. You can iterate through the NestedViewItems in the grid using a recursive method, starting from the MasterTableView (note that the proper place to make the loop is the PreRender handler of the grid):

When HieararchyLoadMode of the relevant GridTableView is "Client" or "ServerBind" a much easier approach could be used. The RadGrid.Items collection contains all items from all tables in the hierarchical structure of Telerik RadGrid. By simply looping through the collection you can access all data-bound items and their controls:

Looping through the detail tables/items in Telerik RadGrid on the client

You can also loop through the available GridTableView and GridDataItem client objects of a hierarchical RadGrid. Using the client API of the control, you can access the detail tables and items through a recursion similar to that inside the LoopHierarchyRecursive server-side method described above.

CopyJavaScript
<script type="text/javascript">
    function pageLoad() {
        var grid = $find('<%=RadGrid1.ClientID %>');
        var masterTable = grid.get_masterTableView();
        traverseChildTables(masterTable);
    }

    function traverseChildTables(gridTableView) {
        var dataItems = gridTableView.get_dataItems();
        for (var i = 0; i < dataItems.length; i++) {
            if (dataItems[i].get_nestedViews().length > 0) {
                var nestedView = dataItems[i].get_nestedViews()[0];
                //here you can access the nested table's data items using nestedView.get_dataItems()
                alert(nestedView.get_name());
                traverseChildTables(nestedView);
            }
        }
    }
</script>