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.
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.
I have created 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.
A ready-to-use assembly (including help file).
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
Bugfix: Under some conditions, UserControls still could not be reloaded when the application is configured as a website
Bugfix: UserControls could not be reloaded when the application is configured as a website (as opposed to virt.dir.) (thanks to Keith Culpepper)
Bugfix: fixed regression if ShowHeader=false and AllowPaging=false, colspan is wrong (thanks to Stuart Hilbert)
Bugfix: resolved compatibility issue with ASP.NET 2.0
Feature: TemplateDataMode.RunTime makes it possible to choose between SingleRow and Table for each relation at runtime (thanks to Tom Schmidt)
Feature: child templates are displayed for rows in selected state (thanks to Patrick Martin)
Bugfix: state of Checkboxes in child templates is now correctly preserved (thanks to Paolo Falabella)
Bugfix: corrected Mozilla DHTML incompatibilities (thanks to David Tétreault)
Bugfix: corrected problem with non-unique IDs that were generated for "ChildTemplate" panel in a DataMode=Table HierarGrid
Bugfix: child templates were inserted into first column when PagerStyle was set to "Top"
Bugfix: resetting the DataItem after inserting the child templates for further custom processing
Bugfix: copying selected state for <select> tags
Feature: nested HierarGrids now possibly with more than 3 levels (thanks to Matt Petteys)
Bugfix: RowExpanded[x] = false was ignored
Bugfix: excluded RowExpanded property from Designer's Property view
Bugfix: changed Namespace for internal DynamicControlsPlaceholder to avoid conflicts when using both HierarGrid and DCP in one solution (thanks to Matt Bornstein)
Feature: keeps rowstate (expanded/collapsed) between postbacks
Feature: property "RowExpanded" to initially expand rows
Bugfix: HierarColumn not added to Columns collection
Bugfix: Exception with DataViews as DataSource and TemplateDataMode=Table
Bugfix: When TemplateDataMode=Table and DataSet.EnforceContraints=true an exception occured
Bugfix: Designer declaration corrected
Bugfix: corrected JavaScript to allow ShowHeader=False for the Grid
Bugfix: problem solved when TemplateDataMode=Table and DataSource was set to DataSet instead of DataTable
Feature: added support for Netscape and Opera
Feature: added support for nested HierarGrids Bugfix: Exception when calling DataBind twice within one Request Bugfix: Wrong PostData for TextBoxes in a child template
Initial version
Hits on this page: 127453