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

Hierarchical grid with DetailTable datasource as property of main object

1 Answer 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kman
Top achievements
Rank 1
kman asked on 30 Nov 2010, 07:46 PM
Is it possible to have a hierarchical RadGrid where the DetailTable is bound to a property from the Master's data object?

For example, my RadGrid (MasterTableView) is bound to an ObjectDataSource.  The select method returns a collection of Customer objects.  Each Customer object has a collection of Account objects (simple one-to-many relationship).

Obviously my MasterTableView displays the Customer columns and I'd like to simply display all the Accounts in a nested or detail-style table indented underneath.

Where I'm getting confused is whether or not the DetailTable (GridTableView) must use another datasource.

It seems inefficient to have to make additional trips to the database to lookup the accounts for each individual Customer when I already have everything I need.

I think I'm basically wanting to somehow bind my DetailTables (GridViewTable) DataSource to the Accounts property..  but the only option I see is to point it to a completely different DataSourceId.

This is a trimmed-down version of my RadGrid and what I'm basically trying to achieve.  (I know the DataSource property shown on the GridTableView isn't valid - this is just me trying to show what I'd like to do.)

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="objCustomers"
    AutoGenerateColumns="False">
    <MasterTableView DataSourceID="objCustomers" DataKeyNames="CustomerId">       
        <Columns>         
            <telerik:GridBoundColumn DataField="FName" />
            <telerik:GridBoundColumn DataField="LName" />
        </Columns>   
        <DetailTables>                           
            <telerik:GridTableView DataKeyNames="AccountId" DataSource='<% Eval(Accounts) %>' />
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="CustomerId" MasterKeyField="CustomerId" />
                </ParentTableRelation>
                <Columns>
                    <telerik:GridBoundColumn DataField="Type" />
                    <telerik:GridBoundColumn DataField="AcctNum" />
                </Columns>
            </telerik:GridTableView>
        </DetailTables>       
    </MasterTableView>
</telerik:RadGrid>


The Customer Object is basically
CustomerId   (key)
FName
LName
Accounts (collection of Account objects)
Account object is basically:
AccountId (key)
CustomerId (foreign key)
Type
AcctNum


Any guidance would be appreciated.

Thanks-
Kenneth

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Dec 2010, 08:58 AM
Hello Kenneth,

In order to achieve this you can attach the DetailTableDataBind event to RadGrid. In the DetailTableDataBind handler, you should assign datasources for the Detail tables.
For more information on this please go through the following Demo.
Grid / Programmatic Binding

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