Click here to Skip to main content
12,894,339 members (63,602 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 16 Mar 2009

Nested Collapsible Repeater

, 16 Mar 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
A nested repeater control.


The Repeater control available with the .NET Framework does a pretty good job of templated data-binding. But, it does not support data binding with hierarchical data sources. In ASP.NET, data binding will essentially bind data to a server-side control that will then render that data in some form to the client. The server-side control must support a property called DataSource and a method called DataBind(), and the data source to which the control is bound implements the IEnumerable (IHierarchicalEnumerable for nested data) interface.

I decided to write a nested Repeater from ground up. The control renders hierarchical data like a treeview, and supports expanding and collapsing nodes. Each node has a header, body, and footer component, each of which can be templated. The control uses a mix of Composition and Rendering to do the job. Using Composition is generally very expensive as server side HTML elements are created for every tag. So, I am using Composition for rendering the header, body, and footer, and Rendering for all the other tags. For client-side behavior, I have implemented an IScriptControl which essentially manages expanding and collapsing the nodes.

Any data source that derives from HierarchicalDataSourceControl can be used to bind to this control; e.g., XMLDataSource, SiteMapDataSource.

Using the code

<?xml version="1.0" encoding="utf-8" ?>
<Item Header="Header" Footer ="Footer">
  Some Text
  <Item Header="Header" Footer ="Footer">

The repeater can be declared in the ASPX file as:

<cc1:RepeaterEx ID="RepeaterEx1" runat="server">
        <div style="background-color: Red">
        <div style="background-color: Yellow">
        <div style="background-color: Green">
<asp:XmlDataSource ID="XmlDataSource1" runat="server" 

   DataFile="~/XMLFile.xml"> </asp:XmlDataSource> 

Please feel free to post your comments and suggestions.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alomgir Miah A
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionUseful, but is it possible to add controls in the xml? Pin
kintz17-Jun-10 7:25
memberkintz17-Jun-10 7:25 
QuestionGood article! Pin
pandian.anna16-Mar-09 6:32
memberpandian.anna16-Mar-09 6:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 16 Mar 2009
Article Copyright 2009 by Alomgir Miah A
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid