Dynamically Populating Submenu

3 posts, 1 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 30 Jul 2008 Link to this post

    I have a RADMenu control that has the following markup in the aspx page:

    1                     <telerik:RadMenu ID="RadMenu1" Runat="server" Flow="Horizontal">  
    2                         <CollapseAnimation Type="OutQuint" Duration="200" /> 
    3                         <Items> 
    4                             <telerik:RadMenuItem Text="Site Menu">  
    5                                 <Items> 
    6                                     <telerik:RadMenuItem Text="Entry Page" NavigateUrl="~/admin/entry.aspx" /> 
    7                                     <telerik:RadMenuItem Text="FAQ">  
    8                                         <Items> 
    9                                             <telerik:RadMenuItem Text="Categories" NavigateUrl="~/admin/faq-categories.aspx" /> 
    10                                             <telerik:RadMenuItem Text="Items" NavigateUrl="~/admin/faq.aspx" /> 
    11                                         </Items> 
    12                                     </telerik:RadMenuItem> 
    13                                     <telerik:RadMenuItem Text="Helpful Tips" NavigateUrl="~/admin/helpfultip.aspx" /> 
    14                                     <telerik:RadMenuItem Text="Links">  
    15                                         <Items> 
    16                                             <telerik:RadMenuItem Text="Categories" NavigateUrl="~/admin/link-categories.aspx" /> 
    17                                             <telerik:RadMenuItem Text="Items" NavigateUrl="~/admin/link.aspx" /> 
    18                                         </Items> 
    19                                     </telerik:RadMenuItem> 
    20                                     <telerik:RadMenuItem Text="News" NavigateUrl="~/admin/news.aspx" /> 
    21                                     <telerik:RadMenuItem Text="Services" /> 
    22                                 </Items> 
    23                             </telerik:RadMenuItem> 
    24                         </Items> 
    25                     </telerik:RadMenu> 

    What I need to do is append items to the Services menu item based on database fields. I am using LINQ and a HashTable (plus HttpCache) to pull this off with the following code:

    1             Hashtable items = (HttpContext.Current.Cache["Services"] != null) ? (Hashtable)HttpContext.Current.Cache["Services"] : new Hashtable();  
    2  
    3             if (items.Count == 0)  
    4             {  
    5                 using (LemonLawyerDataContext data = new LemonLawyerDataContext())  
    6                 {  
    7                     var services = from s in data.Services orderby s.Name select s;  
    8  
    9                     foreach (Service s in services)  
    10                     {  
    11                         items.Add(s.Id, s.Name);  
    12                     }  
    13                 }  
    14  
    15                 HttpContext.Current.Cache["Services"] = items;  
    16             }  
    17  
    18             foreach (Telerik.Web.UI.RadMenuItem item in this.RadMenu1.Items[0].Items)  
    19             {  
    20                 if (item.Text == "Services")  
    21                 {  
    22                     foreach (DictionaryEntry en in items)  
    23                     {  
    24                         item.Items.Insert(item.Items.Count, new Telerik.Web.UI.RadMenuItem(en.Value.ToString(), "~/admin/services.aspx?serviceid=" + en.Key.ToString()));  
    25                         //item.Items.Add(new Telerik.Web.UI.RadMenuItem(en.Value.ToString(), "~/admin/services.aspx?serviceid=" + en.Key.ToString()));  
    26                     }  
    27                 }  
    28             }  
    29  

    Everything builds great and runs, but the menu only appends the last item in the dictionary object. I've gone through the debugger and confirmed if the cache is null that it gets populated with all items (supposed to be 2) and the final loop tells the menu to append two items but only the last one added shows up. I confirmed this by adding a third Service to the database and now it is the only one that shows up.

    I'm sure I am doing something really simple wrong here, but could someone point me in the right direction?

    PS - The forums site has trouble in FF3 so I am forced to use IE. Any chance this will be resolved soon?
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 31 Jul 2008 Link to this post

    Hello digitall,

    There seems to be nothing wrong from first sight. Can you confirm that there is more than one item in your dictionary? Also what does item.Items.Count report in the debugger?

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 31 Jul 2008 Link to this post

    Albert,

    I have no clue what happened. I went through the debugger like you suggested, it showed the correct number of items under VisibleItemCount and it just started working. Everything is great now even though I didn't change anything.

    Thanks for the quick response though!
Back to Top