Simple nested Repeater controls

Just found a piece of functionality which I’ve never noticed before, for populating nested Repeaters, without doing so in the code behind with a “OnDataBound” Event.

It’s as simple as just setting the DataSource on the child repeater, to a property of the parent repeaters DataItem.  For example;

<asp:Repeater ID="BookRepeater" runat="server"  onitemdatabound="bibRepeater_ItemDataBound">
<h1><%# DataBinder.Eval(Container.DataItem,  "BookTitle")%></h1>
<asp:Repeater ID="AuthorsRepeater" runat="server"  DataSource='<%# ((Book)Container.DataItem).Authors %>'>
<HeaderTemplate><h5>Author: </HeaderTemplate>
<a href='/AuthorDetails.aspx?id=<%#  DataBinder.Eval(Container.DataItem, "Id")%>' title="<%#  DataBinder.Eval(Container.DataItem, "FirstName")%> <%#  DataBinder.Eval(Container.DataItem, "LastName")%>"><%#  DataBinder.Eval(Container.DataItem, "FirstName")%> <%#  DataBinder.Eval(Container.DataItem, "LastName")%></a>
<SeparatorTemplate>, </SeparatorTemplate>

You may need to add a declaration to the namespace in which your entities reside, at the top of your aspx file, like this;

<%@ Import Namespace="Hachette.Entities.Orchard" %>

full details on MSDN; How To Display Hierarchical Data by Using Nested Repeater Controls and Visual C# .NET.

  1. #1 by Chris on July 23, 2012 - 12:50

    I use this same approach on a project I am currently working on. Do you have any idea how to persist this data back to the server, it seems that the data is not being stored in the viewstate.


(will not be published)

I absolutely love these. They came at the lace wigs are good quality, and very soft. Absolutely love these extensions. I just love this hair. Hair came on time, I waited until after hair extensions uk very full, no shedding and it is been installed for 3 weeks now and yes I jus ordered 3 more bundles. Lol. I definitely recommend this company for your bundles ladies. They are soft, hair bundles on the head for human hair wigs and I would continue to recommend them. I have thinner hair so they cover and blend nicely.