This is a migrated thread and some comments may be shown as answers.
RadMenu with databinding and dynamic templates
4 Answers 162 Views
This is a migrated thread and some comments may be shown as answers.
Carlos Amigo
Top achievements
Rank 1
Carlos Amigo asked on 18 Feb 2010, 12:13 AM
Hi guys. I need to implement this ajax funtionallity.
I've a RadMenu databinded with SQL Server.
When I put the mouse pointer over the last menuitem of one hierarchy, I need to pass a custom attribute with a URL to a WCF service and populate a Menu Template with all data returned, (this comes from a document library of sharepoint).
How i can to do this?

Thanks

Charly

4 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 19 Feb 2010, 01:55 PM
Hello Carlos,

There is an online demo with web services:
http://demos.telerik.com/aspnet-ajax-beta/menu/examples/programming/webservice/defaultcs.aspx

I hope it helps you get started.


Greetings,
Peter
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.
0
Carlos Amigo
Top achievements
Rank 1
answered on 23 Feb 2010, 06:59 PM
Peter: Thank you. Now I've a new chalenge. I'm a table in SQL with the hierarchy of the items, (with ParentId included) databinded to a RadMenu, and I need to show the last two hierarchies of the table, (or menu) in a template menu.
Is this possible?

TIA

Charly
0
Peter
Telerik team
answered on 26 Feb 2010, 08:52 AM
Hello Carlos,

Unfortunately, this scenario is not supported by RadMenu.

Greetings,
Peter
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.
0
Sérgio
Top achievements
Rank 1
answered on 22 Jul 2011, 09:45 AM
Add the "OnDataBound" event on aspx page where we can hide the items on the level 1 (sublevels become autommatically hidden) and add a new item template for each level 0 item. In this example, the template has a RadSiteMap with the menu items of level 1 and level 2.

    protected void RadMenu1_DataBound(object sender, EventArgs e)
    {
        try
        {
            foreach (RadMenuItem item in ((RadMenu)sender).GetAllItems())
            {
                if (item.Level == 0)
                {
                    item.PostBack = false;


                    RadMenuItem siteMap = new RadMenuItem();
                    siteMap.Text = "";
                    siteMap.ItemTemplate = new MenuTemplate();
                    item.Items.Add(siteMap);
                }
                else
                {
                    item.Visible = false;
                }
            }


            foreach (RadMenuItem item in ((RadMenu)sender).GetAllItems())
            {
                if ((item.Level == 1) && (item.Text == ""))
                {
                    item.DataBind();
                }
            }
        }
        catch { }
        finally { }
    }





class MenuTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        RadSiteMap radSiteMap1 = new RadSiteMap();
        radSiteMap1.ID = "RadSiteMap1";
        radSiteMap1.Skin = "Default";
        radSiteMap1.Width = Unit.Pixel(450);
        SiteMapLevelSetting smls = new SiteMapLevelSetting(0);
        smls.ListLayout.RepeatColumns = 1;
        smls.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal;
        radSiteMap1.LevelSettings.Add(smls);
        SiteMapLevelSetting smls1 = new SiteMapLevelSetting(1);
        smls1.ListLayout.RepeatColumns = 4;
        smls1.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal;
        radSiteMap1.LevelSettings.Add(smls1);
        radSiteMap1.DataBinding += new EventHandler(radSiteMap1_DataBinding);
        container.Controls.Add(radSiteMap1);
    }


    private void radSiteMap1_DataBinding(object sender, EventArgs e)
    {
        RadSiteMap target = (RadSiteMap)sender;
        RadMenuItem item = (RadMenuItem)target.BindingContainer;
        RadMenuItem root = ((RadMenuItem)item.Parent);


        for (int i = 0; i < root.Items.Count; i++)
        {
            if (root.Items[i].Text != "")
            {
                RadSiteMapNode nodeParent = new RadSiteMapNode(root.Items[i].Text, "");
                nodeParent.Enabled = false;
                target.Nodes.Add(nodeParent);


                for (int j = 0; j < root.Items[i].Items.Count; j++)
                {
                    nodeParent.Nodes.Add(new RadSiteMapNode(root.Items[i].Items[j].Text, root.Items[i].Items[j].NavigateUrl));
                }
            }
        }
    }


}
Tags
Menu
Asked by
Carlos Amigo
Top achievements
Rank 1
Answers by
Peter
Telerik team
Carlos Amigo
Top achievements
Rank 1
Sérgio
Top achievements
Rank 1
Share this question
or