This is a migrated thread and some comments may be shown as answers.

Mega Drop Down issue

1 Answer 99 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 10 Feb 2012, 01:26 PM
Hi,

Am doing mega drop down menu, where the menu items and sub items are driven from XML file.Actually my wish is drop down should not appear if no sub items are present under a menu item.But in this case am getting an empty drop down.Please let me know how to get out of this.

Code snippet is as folows and the following attachment is my xml file.


        protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RadMenu1.LoadContentFile("menu3.xml");
            RadMenu1.DataBind();


        }  
    }

protected void RadMenu1_DataBound(object sender, EventArgs e)
    {
        RadMenu menu = (RadMenu)sender;
        menu.Width = 880;
        menu.Height = 35;
        foreach (RadMenuItem item in menu.Items)
        {
            RadSiteMap sm = new RadSiteMap();
            PopulateSiteMap(sm, null, item);   

            //sitemap settings to have the menu items appear in columns

            SiteMapLevelSetting rootLevelSetting = new SiteMapLevelSetting(0);
            rootLevelSetting.ListLayout.RepeatColumns = 1;
            rootLevelSetting.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal;
            sm.LevelSettings.Add(rootLevelSetting);
            item.Items.Clear();
            RadMenuItem childItem = new RadMenuItem();


            childItem.Width = 880;
            Panel catWrapper = new Panel();
            catWrapper.CssClass = "Wrapper";
            catWrapper.Width = Unit.Pixel(870);
            catWrapper.Controls.Add(sm);

            childItem.Controls.Add(catWrapper);
            item.Items.Add(childItem);
        }
    }

 private static void PopulateSiteMap(RadSiteMap sm, RadSiteMapNode node, RadMenuItem item)
    {
        if (node == null)
        {
            foreach (RadMenuItem child in item.Items)
            {
                node = new RadSiteMapNode(child.Text, child.NavigateUrl);             
                sm.Nodes.Add(node);
                if (child.Items.Count > 0)
                {
                    PopulateSiteMap(sm, node, child);
                }
            }
        }
        else
        {
            foreach (RadMenuItem child in item.Items)
            {              
                node.Nodes.Add(new RadSiteMapNode(child.Text, child.NavigateUrl));
                if (child.Items.Count > 0)
                {
                    PopulateSiteMap(sm, node, child);
                }
            }
        }       
    }  

Thanks & Regards
Mohanram Poola

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 14 Feb 2012, 01:56 PM
Hello Mohanram,

Please, see this kb article - http://www.telerik.com/support/kb/aspnet-ajax/menu/mega-drop-down-menu-bind-to-xml-datasource.aspx.


Regards,
Peter
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Menu
Asked by
Ram
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or