Search code examples
repeaterinvisible

asp.net nested repeaters


I have some problems with nested repeaters. I have the following markup

<asp:UpdatePanel ID="upSupportDownloads" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="five-col">
            <asp:Repeater ID="rep1" runat="server">
                <ItemTemplate>
                    <asp:Repeater ID="rep2" runat="server">
                        <ItemTemplate></ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:Repeater>  
...

It's not a working code, it's an example to understand my structure. I can't access rep2 from my code behind. I can call rep1. But rep2 is invisible for me.


Solution

  • You need to find the nested repeater in the OnItemDataBound event of your main repeater. like this:

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
         DataRowView row = (DataRowView)e.Item.DataItem;
    
         Repeater nestedRepeater = e.Item.FindControl("NestedRepeater") as Repeater;
         nestedRepeater.DataSource = getMyData();
         nestedRepeater.DataBind();
     }