Binding a transformation dynamically to a nested repeater

DILRUKSHAN FIGURADO asked on December 2, 2014 06:10

I have a transformation which contains a user control as below CMS.MenuItem.MegaMenu

<%@ Register src="/CMSWebparts/Salmat/MegaMenu3.ascx" tagname="Submenu" tagprefix="uc1" %>

  • <%# Eval("DocumentName")%>

    <%# Eval("MenuItemTitle") %>

  • User control code

    I'm trying to bind a transformation and Classname to the rptMenuLevel3 in the OnItemDataBound but it return always null. below code

    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            if (MenuItemType == "1")
            {
                rptMenuLevel2.Path = NodeAliasPath + "/%";
                rptMenuLevel2.ClassNames = "Content.PageProductCategory";
                rptMenuLevel2.TransformationName = "Content.PageProductCategory.MenuItemsMenuTypeOne";
                rptMenuLevel2.ReloadData(true);
            }
        }
    }
    

    protected void rptMenuLevel2_OnItemDataBound(object sender, RepeaterItemEventArgs e) { RepeaterItem item = e.Item;

        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
        {
            var dr = item.DataItem as DataRowView;
            var rptMenuLevel3Item = item.FindControl("rptMenuLevel3") as CMSRepeater;
    
            if (MenuItemType == "1")
            {
                if (rptMenuLevel3Item != null)
                {
                    rptMenuLevel3Item.ClassNames = "Content.PageProduct";
                    rptMenuLevel3Item.TransformationName = "Content.PageProduct.MenuItem";
                    rptMenuLevel3Item.ReloadData(true);
                }
            }
        }
    }
    

    Recent Answers


    Brenden Kehren answered on December 2, 2014 06:42

    • What version are you using?

    • Where is this code located (SetupControl and OnItemDataBound)?

    • Are you using a standard Kentico repeater control?

    A hierarchical viewer/transformation will perform much better and you won't have to write any "fancy" webparts or nest repeaters.

    1 votesVote for this answer Mark as a Correct answer

    DILRUKSHAN FIGURADO answered on December 2, 2014 07:12

    Hi Brenden,

    Thank you for replying,

    I'm using Kentico 8.1, Code is located in the .cs file of the user control and I'm using CMSRepeater control. my main senario is I have a mega-menu which displays various document types and each hover state displays sub levels in different lay outs

    example

    What we do (MenuItem) | |--->Digital (Product Category) => The product category lay out is different from Solution Category | |---eCommerce (Product)

    What you want
    | |---->Find Customer (Solution Category) => The solution category layout is different from Product category | |-----> Build Brand Awareness (Solution)

    If user changes the "MenuType" from dropdown then the mega menu layout needs to be changes.

    example : If menu type is changed to TYPE-1 from being TYPE-2. Then the layout should change as well.

    0 votesVote for this answer Mark as a Correct answer

    Sandro Jankovic answered on December 2, 2014 09:42

    Hello,

    As Brenden suggested it may be better to configure a hierarchical viewer for this purpose but if you would like to continue with your approach the documentation may help determine if you are missing any steps. Specifically, have you set the DelayedLoading for the nested control?

    Please let me know if you have any additional questions or information.

    Best Regards,

    Sandro

    0 votesVote for this answer Mark as a Correct answer

       Please, sign in to be able to submit a new answer.