select

Grid / Declarative Relations

Rate this demo: Feedback
Run example in: C# VB.NET Change Skin:
Vista
  • BlackBlack
  • DefaultDefault
  • ForestForest
  • HayHay
  • Office2007Office2007
  • OutlookOutlook
  • SimpleSimple
  • SitefinitySitefinity
  • SunsetSunset
  • TelerikTelerik
  • VistaVista
  • Web20Web20
  • WebBlueWebBlue
  • Windows7Windows7
 CustomerIDContact NameCompany 
 Page 1 of 13, items 1 to 7 of 91.
ALFKIMaria AndersAlfreds Futterkiste
 
 OrderIDDate Ordered Freight
10643Monday, August 25, 199729.46
 
Unit PriceQuantity Discount
18.00210.25
45.60150.25
12.0020.25
10692Friday, October 03, 199761.02
10702Monday, October 13, 199723.94
10835Thursday, January 15, 199869.53
10952Monday, March 16, 199840.42
11011Thursday, April 09, 19981.21
ANATRAna TrujilloAna Trujillo Emparedados y helados
ANTONAntonio MorenoAntonio Moreno Taquería
AROUTThomas HardyAround the Horn
BERGSChristina BerglundBerglunds snabbköp
BLAUSHanna MoosBlauer See Delikatessen
BLONPFrédérique CiteauxBlondesddsl père et fils

Example Source Code & Description

Instructions
Open in new window
  • 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>
    <telerik:GridRelationFields DetailKeyField="ID1" MasterKeyField="ID1" />
    <telerik:GridRelationFields DetailKeyField="ID2" MasterKeyField="ID2" />
    <telerik: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
Compatible with ASP.NET 2.0, 3.5 AJAX enabled Accessibility Verified!Valid XHTML 1.1! Optimized for Visual Studio 2005, 2008
Copyright 2002-2010 © Telerik. All right reserved  | 
Telerik Inc., 460 Totten Pond Rd, Suite 640, Waltham, MA 02451

www.telerik.com  |  Terms of Use  |  Contact Us