Search code examples
c#asp.netrepeater

Nested Repeaters - have 3 repeaters


I understand the OnItemDatabound attribute on the Parent Repeater ... makes sense

Here is my question:

lets say my data is structured as follows:

<List>
Parent Level Movie String
   Next Level : Amenities <List>
       Next level:   Showtimes <List>

So I was creating a List of Movies, within that list of Movies is a List of Amenities, within that list of Amenities is the Showtimes

 Movies is Repeater 1
 Amenities is Repeater 2 Child of Repeater 1
 Showtimes is Repeater 3 Child of Repeater 2

So, my question is Movies is in a list, and each of the different Repeater items are in a list, can those lists just be used as the DataSource for each Child Repeater, since the data is already contained.


Solution

  • Yes, they can. It's not even hard. Your markup can just look something like this:

    <asp:Repeater runat="server">
        <ItemTemplate>
            <asp:Label runat="server" Text='<%# Eval("Title") %>' />
    
            <asp:Repeater runat="server" DataSource="Amenities ">
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("SomeField") %>' />
    
                    <asp:Repeater runat="server" DataSource="Showtimes">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" 
                                Text='<%# Eval("SomeOtherField") %>' />
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:Repeater>