0
votes

I have implemented web part to support nested repeaters in order to implement mega menu using kentico 8

What I did was created following repeaters in web part

<div>
    <cms:CMSRepeater ID="CMSRepeater6" runat="server" Path="/%" ClassNames="CMS.MenuItem" OrderBy="NodeOrder" WhereCondition="DocumentMenuItemHideInNavigation = 0 AND Published = 1 AND MenuItemGroup='Top'" MaxRelativeLevel="1" DelayedLoading="true"  OnItemDataBound="CMSRepeater6_ItemDataBound" >
        <ItemTemplate>
            <div>
                <li>
                    <h3><a href="<%# Eval("NodeAliasPath")%>"><%# Eval("DocumentName")%></a></h3>
                </li>
            </div>
            <cms:CMSRepeater ID="repMegaMenuLevel1" runat="server" Path="/%" ClassNames="CMS.MenuItem" OrderBy="NodeOrder">
                 <ItemTemplate>
                </ItemTemplate>
            </cms:CMSRepeater>
        </ItemTemplate>
    </cms:CMSRepeater>
</div>

And tried to bind the transformation in code level

protected void CMSRepeater6_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem item = e.Item;
        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
        {
            var dr = item.DataItem as DataRowView;
            string menuType = dr["MenuItemType"].ToString();

            if (!string.IsNullOrEmpty(menuType))
            {
               var rptMegaMenuItem = item.FindControl("repMegaMenuLevel1") as CMSRepeater;

                if (menuType.Equals("1"))
                {
                    rptMegaMenuItem.TransformationName = "Content.PageProductCategory.MagaMenu11";
                    rptMegaMenuItem.WhereCondition = "MenuItemType = 1 AND MenuItemGroup='Top' AND DocumentMenuItemHideInNavigation = 0 ";
                    rptMegaMenuItem.NestedControlsID = "repMegaMenuLevel3";
                    rptMegaMenuItem.DelayedLoading = true;

                }

            }

        }
    }

Transformation code:

<cms:CMSRepeater ID="repMegaMenuLevel3" runat="server" DataBindByDefault="false" EnableViewState="false" ClassNames="Content.PageProductCategory;CMS.MenuItem" MaxRelativeLevel="1" Path="/What-we-do/%">
    <ItemTemplate>
        <li><%# Eval("DocumentName")%></li> 
        <li><%# Eval("DocumentNamePath")%></li>
      <li><%# Eval("ClassName")%></li>
    </ItemTemplate>
</cms:CMSRepeater>
<script runat="server">
  protected override void OnInit(EventArgs e) {
    repMegaMenuLevel3.Path = "/What-we-do/%";
    repMegaMenuLevel3.ClassNames="Content.PageProductCategory";
    repMegaMenuLevel3.ReloadData(true);  
  }
</script>

The issue is that the repeater repMegaMenuLevel3 always returned the Document Name as the parents (CMS.MenuItem) DocumentName i.e "What we do" not from the content.PageProductCategory, I tried by setting the paths in different manner, but no luck

1

1 Answers

0
votes

I have a feeling that you unnecessarily set too much properties :)

  1. Use NestedControlsID correctly - when a parent control has it set avoid setting Path on child controls.
  2. Also avoid calling ReloadData(true) on child controls - parent control will do that for you
  3. Consolidate usage of ClassNames (I'd recommend to set it only in ASPX markup)
  4. Get rid of custom _ItemDataBound - try to move your code to the transformation

If you want to try different approach I'd recommend using hierarchical transformations.

Resources: