This example demonstrates how to programmatically build hierarchical structures
with Telerik RadGrid:
- Creating hierarchical grid at runtime from scratch - no code in ascx
- Using the RadGrid.MasterTableView property and the GridTableView class
- Adding columns to grid views
- Building 3-level hierarchy and binding the grid using the NeedDataSource
and
DetailTablesDataBind events
In essence, there are two possible means to build Telerik RadGrid programmatically:
-
Create the control entirely in the code behind. This means that the grid instance should be created in the PageInit
handler and added to a place holder's Controls collection at runtime, after the structure has been created. Note that in this case
the grid columns should be added to the Controls collection of the MasterTableView after their attributes are set.
No ViewState is required for grid structure to be persisted as it is recreated on each page initialization.
-
Create the control statically, but add its structure dynamically. This has to take place in the PageLoad event handler,
following the rules for a structure object: columns or detail tables should be added to the corresponding collection first
and then values for the properties of this instance should be set. Remember to check the condition (Not IsPostBack) to avoid adding
the same structure objects to the grid twice. This is important because no ViewState is managed for the object before it has been added to
the corresponding collection.
Note that hierarchical 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.
More about the conventions about how to generate Telerik RadGrid structure programmatically
you can find in the online documentation:
Creating hierarchical grid programmatically