HierarGrid - A hierarchical DataGrid that displays master-detail relations
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 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
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.
History:V126.96.36.199 (published 2006-05-12)
Bugfix: Under some conditions, UserControls still could not be reloaded when the application is configured as a website
V188.8.131.52 (published 2006-01-11)
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)
V184.108.40.206 (published 2005-12-18)
Bugfix: resolved compatibility issue with ASP.NET 2.0
V220.127.116.11 (published 2004-08-07)
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)
V18.104.22.168 (published 2004-05-30)
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
V22.214.171.124 (published 2003-10-17)
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)
V126.96.36.199 (published 2003-09-07)
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
V188.8.131.52 (published 2003-08-25)
Bugfix: problem solved when TemplateDataMode=Table and DataSource was set to DataSet instead of DataTable
V184.108.40.206 (published 2003-04-26)
Feature: added support for Netscape and Opera
V220.127.116.11 (published 2003-04-25)
Feature: added support for nested HierarGrids
Bugfix: Exception when calling DataBind twice within one Request
Bugfix: Wrong PostData for TextBoxes in a child template
V18.104.22.168 (published 2003-03-04)
- DataBind is called automatically for child templates (by design)
- if the row order or the page index changes between postbacks a wrong row may be expanded as the row state is stored by index. This issue is by design and can be worked around by calling HG.RowExpanded.CollapseAll()
- UserControls with "_" in the filename:
Unfortunatley, the DCP (that is used internally) cannot recreate UserControls whose filename contains "_" and other special characters. Furthermore, it doesn't work if a custom ClassName is given in the ASCX file.