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

Dynamically Populating Submenu

2 Answers 108 Views
Menu
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 31 Jul 2008, 01:13 AM
I have a RADMenu control that has the following markup in the aspx page:

                    <telerik:RadMenu ID="RadMenu1" Runat="server" Flow="Horizontal">  
                        <CollapseAnimation Type="OutQuint" Duration="200" /> 
                        <Items> 
                            <telerik:RadMenuItem Text="Site Menu">  
                                <Items> 
                                    <telerik:RadMenuItem Text="Entry Page" NavigateUrl="~/admin/entry.aspx" /> 
                                    <telerik:RadMenuItem Text="FAQ">  
                                        <Items> 
                                            <telerik:RadMenuItem Text="Categories" NavigateUrl="~/admin/faq-categories.aspx" /> 
                                            <telerik:RadMenuItem Text="Items" NavigateUrl="~/admin/faq.aspx" /> 
                                        </Items> 
                                    </telerik:RadMenuItem> 
                                    <telerik:RadMenuItem Text="Helpful Tips" NavigateUrl="~/admin/helpfultip.aspx" /> 
                                    <telerik:RadMenuItem Text="Links">  
                                        <Items> 
                                            <telerik:RadMenuItem Text="Categories" NavigateUrl="~/admin/link-categories.aspx" /> 
                                            <telerik:RadMenuItem Text="Items" NavigateUrl="~/admin/link.aspx" /> 
                                        </Items> 
                                    </telerik:RadMenuItem> 
                                    <telerik:RadMenuItem Text="News" NavigateUrl="~/admin/news.aspx" /> 
                                    <telerik:RadMenuItem Text="Services" /> 
                                </Items> 
                            </telerik:RadMenuItem> 
                        </Items> 
                    </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:

            Hashtable items = (HttpContext.Current.Cache["Services"] != null) ? (Hashtable)HttpContext.Current.Cache["Services"] : new Hashtable();  
 
            if (items.Count == 0)  
            {  
                using (LemonLawyerDataContext data = new LemonLawyerDataContext())  
                {  
                    var services = from s in data.Services orderby s.Name select s;  
 
                    foreach (Service s in services)  
                    {  
                        items.Add(s.Id, s.Name);  
                    }  
                }  
 
                HttpContext.Current.Cache["Services"] = items;  
            }  
 
            foreach (Telerik.Web.UI.RadMenuItem item in this.RadMenu1.Items[0].Items)  
            {  
                if (item.Text == "Services")  
                {  
                    foreach (DictionaryEntry en in items)  
                    {  
                        item.Items.Insert(item.Items.Count, new Telerik.Web.UI.RadMenuItem(en.Value.ToString(), "~/admin/services.aspx?serviceid=" + en.Key.ToString()));  
                        //item.Items.Add(new Telerik.Web.UI.RadMenuItem(en.Value.ToString(), "~/admin/services.aspx?serviceid=" + en.Key.ToString()));  
                    }  
                }  
            }  
 

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 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 31 Jul 2008, 06:28 AM
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.
0
digitall
Top achievements
Rank 1
answered on 01 Aug 2008, 12:32 AM
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!
Tags
Menu
Asked by
digitall
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
digitall
Top achievements
Rank 1
Share this question
or