Problem:
The ASP.NET DataGrid is a popular control to display data in a table form with editing, paging and sorting capabilites.
However it is only suitable to display single DataTables - there is no support for parent-child relations.
Goal:
To create a control that provides the standard DataGrid functionality and at the same time can display parent-child relations using templates to display the child elements.
Procedure:
Create a custom control called HierarGrid that derives from the DataGrid and a custom DataGridColumn called HierarColumn.
The HierarGrid takes a DataSet that contains relations between the tables.
While iterating over the parent table it checks the related tables for child rows and if one is found it dynamically loads a template for the child
row(s)The template is rendered invisibly into the custom HierarColumn and when the user clicks the plus icon, the template content is copied via JavaScript into a newly created TableRow.
Download (V2.2):
- The sourcecode is available in C# as a VS.NET 2002 project.
-
A ready-to-use assembly (including help file).
How to get started:
-
A step-by-step tutorial that explains the usage of the HierarGrid is available on ASPAlliance
-
The demo that is mentioned in the article shows the usage of this control.
Sourcecode for the Demo (C#) or Sourcecode for the Demo (VB) -
A really advanced sample application with documentation that shows filtering, sorting, paging, exporting with the HierarGrid was written by Nigel Parham. Please note that it is provided as-is like all downloads on this site.
-
A simple demo that shows editing in the HierarGrid.
-
And finally some snapshots showing real-life samples of the HierarGrid: Snapshot 1 Snapshot 2 Snapshot 3
0 comments:
Post a Comment