Pergunta

Using the Kentico CMS framework (version 7) how would one go about nesting multiple CMS Repeaters?

I've tried the following which binds the parent but how would you then get the children to bind?

<cms:CMSRepeater ID="repProducts" runat="server" ClassNames="cms.product" OrderBy="NodeLevel,NodeOrder" SelectOnlyPublished="true"  MaxRelativeLevel="1">
<ItemTemplate>
      <%# Eval("DocumentName")%>
      <ul>
            <li>
                     <cms:CMSRepeater ID="repProductsNested" runat="server" ClassNames="cms.product" OrderBy="NodeLevel,NodeOrder" SelectOnlyPublished="true"  MaxRelativeLevel="1" Path="./%">
                     <HeaderTemplate>
                            <ul>
                     </HeaderTemplate>
                     <ItemTemplate>
                            <li><%# Eval("DocumentName")%>
                     </ItemTemplate>
                     </cms:CMSRepeater>
                     <FooterTemplate>
                            </ul>
                     </FooterTemplate>
            </li>
      </ul>
</ItemTemplate>
</cms:CMSRepeater>
Foi útil?

Solução

I think you are missing two vital attributes on your first repeater that is DelayedLoading="true" and NestedControlsID="repProductsNested" therefore your code should look as follows:

<cms:CMSRepeater ID="repProducts" runat="server" ClassNames="cms.product" OrderBy="NodeLevel,NodeOrder" SelectOnlyPublished="true"  MaxRelativeLevel="1" NestedControlsID="repProductsNested" DelayedLoading="true">
<ItemTemplate>
      <%# Eval("DocumentName")%>
      <ul>
            <li>
                     <cms:CMSRepeater ID="repProductsNested" runat="server" ClassNames="cms.product" OrderBy="NodeLevel,NodeOrder" SelectOnlyPublished="true"  MaxRelativeLevel="1" Path="./%">
                     <HeaderTemplate>
                            <ul>
                     </HeaderTemplate>
                     <ItemTemplate>
                            <li><%# Eval("DocumentName")%>
                     </ItemTemplate>
                     </cms:CMSRepeater>
                     <FooterTemplate>
                            </ul>
                     </FooterTemplate>
            </li>
      </ul>
</ItemTemplate>
</cms:CMSRepeater>

Outras dicas

As a side point to this, I'd strongly advise NOT using nested repeaters unless you really have to, or your data set is fairly small. We had a large drop down menu spanning three levels deep on one of our sites which worked this way. The site was experiencing performance problems and after investigating why, the menu was found to be the culprit because of it's many many data bindings. Changing it to use a hierarchical viewer fixed this because it returns a single dataset which can be manipulated with hierarchical transformations.

I think you should look into hierarchical transformations whenever nested repeaters are a possibility.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top