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

[Solved] Linked Menus

1 Answer 97 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 09 Jun 2009, 02:48 PM
I have 2 menus on a simple ASPX page.  A top menu and a left menu.  The left menu is a subset of data from the item I click on in the top menu.

I can get this to work properly, but ONLY on the first item I click on in the top menu.  After that, the left menu only displays the initial data even though I rebind the menu with the new data set.

Here is my code:
ASPX: 
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadMenu ID="mainRadMenu" runat="server" DataSourceID="mainRadMenuXDS" DataTextField="title" OnItemClick="mainRadMenu_ItemClick" PostBackUrl="~/Test.aspx"
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </telerik:RadMenu> 
        <asp:XmlDataSource ID="mainRadMenuXDS" runat="server" DataFile="~/App_Data/XMLFile1.xml" XPath="/Items/Item" /> 
        <br /> 
        <br /> 
        <br /> 
        <br /> 
        <br /> 
        <telerik:RadMenu ID="leftRadMenu" runat="server" Flow="Vertical"
            <DefaultGroupSettings Flow="Horizontal" /> 
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </telerik:RadMenu> 
        <asp:XmlDataSource ID="leftRadMenuXDS" runat="server" XPath="/Items/Item" /> 
 
CS: 
protected void mainRadMenu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e) 
        { 
            Session["MainMenu"] = e.Item.Text; 
 
            PopulateLeftMenu(); 
        } 
 
        protected void PopulateLeftMenu() 
        { 
            XmlDocument xmldoc = new XmlDocument(); 
            xmldoc.Load(Server.MapPath("~/App_Data/XMLFile1.xml")); 
 
 
            XmlNode mainMenuItem = xmldoc.SelectSingleNode(String.Format("//Items//Item[@title = '{0}']", Session["MainMenu"].ToString())); 
 
            XmlDocument leftMenuDocument = new XmlDocument(); 
            leftMenuDocument.LoadXml(String.Format("<Items>{0}</Items>", mainMenuItem.InnerXml.ToString())); 
 
            leftRadMenuXDS.Data = leftMenuDocument.InnerXml; 
            leftRadMenu.DataSourceID = leftRadMenuXDS.UniqueID; 
            leftRadMenu.DataTextField = "title"
            leftRadMenu.DataBind(); 
        } 
XML: 
<?xml version="1.0" encoding="utf-8" ?> 
<Items> 
    <Item title="Menu 1" description=""
        <Item title="Menu 1A" description="" /> 
        <Item title="Menu 1B" description=""
            <Item title="Menu 1B1" description="" /> 
            <Item title="Menu 1B2" description="" /> 
            <Item title="Menu 1B3" description="" /> 
            <Item title="Menu 1B4" description="" /> 
            <Item title="Menu 1B5" description="" /> 
        </Item> 
        <Item title="Menu 1C" description="" />      
    </Item> 
    <Item title="Menu 2" description=""
        <Item title="Menu 2A" description="" /> 
        <Item title="Menu 2B" description="" />      
    </Item> 
    <Item title="Menu 3" description=""
        <Item title="Menu 3A" description="" /> 
        <Item title="Menu 3B" description="" /> 
        <Item title="Menu 3C" description="" /> 
        <Item title="Menu 3D" description="" /> 
    </Item> 
    <Item title="Menu 4" description=""
        <Item title="Menu 4A" description="" /> 
        <Item title="Menu 4B" description="" /> 
        <Item title="Menu 4C" description="" /> 
        <Item title="Menu 4D" description="" /> 
    </Item> 
    <Item title="Menu 5" description="" /> 
</Items> 


I can see when I debug, that the left menu has no data in it and that the correct data is being databound to it, however I always end up with the inital data.

Any thoughts or suggestions would be GREATLY appreciated!

1 Answer, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 10 Jun 2009, 11:00 AM
Hello Michael,

In order to achieve your goal you should disable the XmlDataSource caching:

protected void PopulateLeftMenu()  
    {  
        XmlDocument xmldoc = new XmlDocument();  
        xmldoc.Load(Server.MapPath("~/XMLFile.xml"));  
 
        XmlNode mainMenuItem = xmldoc.SelectSingleNode(String.Format("//Items//Item[@title = '{0}']", Session["MainMenu"].ToString()));  
 
        XmlDocument leftMenuDocument = new XmlDocument();  
        leftMenuDocument.LoadXml(String.Format("<Items>{0}</Items>", mainMenuItem.InnerXml.ToString()));  
 
        leftRadMenuXDS.Data = leftMenuDocument.InnerXml;  
        leftRadMenuXDS.EnableCaching = false;  
          
        leftRadMenu.DataSource = leftRadMenuXDS;  
        leftRadMenu.DataTextField = "title";  
        leftRadMenu.Items.Clear();  
        leftRadMenu.DataBind();  
    } 


Kind regards,
Paul
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Menu
Asked by
Michael
Top achievements
Rank 1
Answers by
Paul
Telerik team
Share this question
or