+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Dynamic Rad MegaDropDown

Dynamic Rad MegaDropDown

6 posts, 0 answered
  1. Vijaianand
    Vijaianand avatar
    94 posts
    Registered:
    09 Jul 2012
    15 Jul 2010
    Link to this post
    I checked out the Mega drop down which uses RadMenu and RadSiuteMap to build a nice menu. But all the menu items are static. How can we do a dynamic menu driven by database using the Sitemap already existing? Any examples would help.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Jul 2010
    Link to this post
    Hello VIJAIANAND,

    You have to bind a RadMenu control to a SiteMapDataSource. Then on ItemDataBound event add a child RadMenuItem to the item being bound.  Instantiate custom ItemTemplate in the child Item.

    In the ItemTemplate add a div with some text. Then add a SiteMapDataSource and a RadSiteMap bound to it.

    sample code

    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
    <telerik:RadMenu ID="RadMenu1" runat="server" DataSourceID="SitemapDataSource1" MaxDataBindDepth="1">
    </telerik:RadMenu>

    protected void Page_Load(object sender, EventArgs e)
    {
        RadMenu1.ItemDataBound += new Telerik.Web.UI.RadMenuEventHandler(RadMenu1_ItemDataBound);
    }
     
    void RadMenu1_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)
    {
        RadMenuItem childItem = new RadMenuItem();
        e.Item.Items.Add(childItem);
        MenuItemTemplate menuItemTemplate = new MenuItemTemplate();
        menuItemTemplate.InstantiateIn(childItem);
    }
     
    class MenuItemTemplate : ITemplate
    {
        #region ITemplate Members
     
        public void InstantiateIn(Control container)
        {
            RadMenuItem parentItem = (RadMenuItem) container.Parent;
            HtmlGenericControl div = new HtmlGenericControl("div");
            div.ID = "TextDiv";
            div.InnerText = parentItem.Text + " item template";
            //add the div to the container controls
            container.Controls.Add(div);
     
            SiteMapDataSource sitemapDataSource2 = new SiteMapDataSource();
            sitemapDataSource2.ID = parentItem.Text + "dataSource";
            sitemapDataSource2.StartingNodeUrl = parentItem.NavigateUrl;
            //add the SiteMapDataSource control to the container controls collection
            container.Controls.Add(sitemapDataSource2);
             
            RadSiteMap radSitemap = new RadSiteMap();
            radSitemap.ID = parentItem.TabIndex + "siteMap";
            radSitemap.DataSource = sitemapDataSource2;
            radSitemap.DataBind();
            //add the RadSiteMap control to the container controls collection
            container.Controls.Add(radSitemap);
     
        }
     
        #endregion
    }

    Note that this scenario is suitable if you bind the control up to 50-60 pages

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Vijaianand
    Vijaianand avatar
    94 posts
    Registered:
    09 Jul 2012
    16 Jul 2010
    Link to this post
    Ivan,

    Thanks for quick response. I tried converting the code to vb.net and facing some issues. It would be helpful if you can give a vb.net code snippet.

    Also, I need to do some business check and manipulate the menu accordingly and I hope that should be able to do it by removing or adding the menuitem in the radmenu accordingly.

    Vijai
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Jul 2010
    Link to this post
    Hi VIJAIANAND,

    You can use http://converter.telerik.com/ to convert the code

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Vijaianand
    Vijaianand avatar
    94 posts
    Registered:
    09 Jul 2012
    16 Jul 2010
    Link to this post
    I tried and it worked 75% but still having issues resolving some errors.

    RadMenu1.ItemDataBound += new Telerik.Web.UI.RadMenuEventHandler(RadMenu1_ItemDataBound)
    I still get in the above statement saying, need to use RaiseEvent().

    Also it is not recognizing RadSiteMap even after I imported Telerik.Web.UI. Is it in a different namespace?

    Vijai
  6. Vijaianand
    Vijaianand avatar
    94 posts
    Registered:
    09 Jul 2012
    16 Jul 2010
    Link to this post
    Ivan,

    I fixed the RadSitemap issue. I had old Telerik.web.Ui.dll which doesn't have this control and need to copy the new one. I have done this before and figured out that may be the problem.

    Now, help me with the Event trigger. I am still having error saying need to use RaiseEvent.

    RadMenu1.ItemDataBound += new Telerik.Web.UI.RadMenuEventHandler(RadMenu1_ItemDataBound)

    I tried that too but no luck. Am I missing any code?
    Please help me.
    Vijai
Register for webinar
6 posts, 0 answered