Hierarchical Repeater ASP.NET control

Posted at Sun, 23 Oct 2005 21:08:18 GMT by Wilco Bauwer

Out of the box, ASP.NET does not provide a control for displaying hierarchical data (besides the TreeView/Menu, which is not what I want). I just wanted to display hierarchical data in a simple way. Therefore I decided to extend the Repeater control and add support for binding against hierarchical data (ie. data where items have a parent-child relationship).

You can see the results by going to the HierarchicalRepeater demo. It contains a link to the source of that page, to give you an idea of how it works from a page developer's point of view. You can also go to the toolbox and download the latest version of the Wilco.Web library which includes this control (and the source code). Enjoy.

I'd be interested to know how TreeView (or an extended TreeView) didn't work for you? Is it that you wanted a templated control?
Bertrand: Repeater is much more powerful.
You can do ItemDataBound, perform complex binding, formatting, etc
Bertrand: The behavior/experience I wanted came (imo) closer to the one provided by the Repeater, than the TreeView. I also don't need a lot of the things provided by the TreeView; I just wanted a control that renders minimal HTML to allow me to take control over the way nesting is styled. Nesting items inside a div, and allowing this div to have a style is all I need.

When I would want anything more than that, the TreeView is probably the way to go. Please note that while my demo may suggest it tries to resemble the TreeView a bit, it is not intended that way. I only added the collapse/expand to give you an idea of how you can get to the child container, and as a test for myself to make sure the control hierarchy is re-created appropriately after postbacks.
Your message will be encoded/formatted when it is displayed. If you want to post code, please put the code inside [code=X][/code] tags, where X is the language of your code (C#, ASPX, SQL, etc).
Name:
Email:
(will be encoded using JavaScript to keep it functional and prevent it from being picked up by spammers)
Url:
 
Message:
3 + 3 =