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">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li>
<h1><%# DataBinder.Eval(Container.DataItem, "BookTitle")%></h1>
<asp:Repeater ID="AuthorsRepeater" runat="server" DataSource='<%# ((Book)Container.DataItem).Authors %>'>
<HeaderTemplate><h5>Author: </HeaderTemplate>
<ItemTemplate>
<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>
</ItemTemplate>
<SeparatorTemplate>, </SeparatorTemplate>
<FooterTemplate></h5></FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
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.
Related posts:
- Using FindControl to find a repeater nested inside a repeater with HeaderTemplate or FooterTemplate defined
- Conditional logic in ListView ItemTemplate with DataBinder.Eval
- Asp.net nested ListView control’s, with edit functionality- example
- Consuming RSS Feeds using ASP.net controls
- Refactoring a web project so you can share user controls across others










