This example shows the advanced hierarchy model of Telerik RadGrid. You can set the table relations declaratively or programmatically
through the
GridTableView.ParentTableRelation property. Each entry in this collection consists of a relation key names. These key names have to be also
populated in each GridTableView
DataKeyNames array. When these properties are specified correctly, Telerik RadGrid will be able to determine the child records of each GridTableView
when the control builds the hierarchy, without handling the DetailTableDataBind event.
You need to define the ParentTableRelations/DataKeyNames for the MasterTableView/GridTableViews
according to the database relations conventions.And here are the exact conventions:
- the primary key column name for each table in the grid source
(used for master/detail table population) should be added to the DataKeyNames
collection of the respective master/detail table
- the MasterKeyField in the GridRelationFields should match the
primary key of the parent table in the corresponding relation
- the DetailKeyField in the GridRelationFields should match the
foreign key of the child table in the corresponding relation
There is one more detail if you use declarative binding using DataSource controls under .NET 2.0:
You should have WHERE clause in the SelectCommand of the data source controls for the nested
tables which to filter the records for them. The WHERE clause should include the
field
from the ParentTableRelation definition between the master/child table. Furthermore,
that same field has to be included in the
SelectParameters of the "inner" data
source controls (with exactly the same
Name and
SessionField value).
An important detail is that every
GridRelationFields should have only one field
name for
DetailKeyField and
MasterKeyField. For multi-hierarchy
relations you can use multiple relation fields as in the example below:
<ParentTableRelation>
<rad:GridRelationFields DetailKeyField="ID1" MasterKeyField="ID1" />
<rad:GridRelationFields DetailKeyField="ID2" MasterKeyField="ID2" />
<rad:GridRelationFields DetailKeyField="ID3" MasterKeyField="ID3" />
</ParentTableRelation>
Note that hierarchical grid structure is not supported with simple data-binding
(calling DataBind()). See the
Simple data binding demo from the
Populating with
data section for more info about the limitations of this binding mode.
Further information about the nature of the declarative relations you can find here:
Declarative relations