Adding Child menu to current Menu structure

Hello Experts,

I have a menu I have created below. I need to add a sub menu to one of the items "menunteg". I am having problems with the syntax of adding the child menu to the parent. Can you please help me. Thanks.

Jeff
Menu Collection

MenuItem menuadmin = new MenuItem();
            MenuItem menuasc = new MenuItem();
            MenuItem menucpni = new MenuItem();
            MenuItem menugu = new MenuItem();
            MenuItem menuimports = new MenuItem();
            MenuItem menuinsight = new MenuItem();
            MenuItem menunteg = new MenuItem();            
            MenuItem menunws = new MenuItem();
            MenuItem menupfo = new MenuItem();
            MenuItem menuqa = new MenuItem();
            MenuItem menuqwest = new MenuItem();
            MenuItem menureports = new MenuItem();
            MenuItem menuroamex = new MenuItem();
            MenuItem menusocial = new MenuItem();
            MenuItem menutt = new MenuItem();

            menuadmin.Text = "Admin";
            menuadmin.NavigateUrl = "~/secure/admin/default.aspx";
            menuasc.Text = "ASC";
            menuasc.NavigateUrl = "~/secure/asc/default.aspx";
            menucpni.Text = "CPNI";
            menucpni.NavigateUrl = "~/secure/cpni/default.aspx";
            menugu.Text = "GU";
            menugu.NavigateUrl = "~/secure/gu/default.aspx";
            menuimports.Text = "Imports";
            menuimports.NavigateUrl = "~/secure/imports/default.aspx";
            menuinsight.Text = "InSight";
            menuinsight.NavigateUrl = "~/secure/insight/default.aspx";
            menunteg.Text = "NTEG";
            menunteg.NavigateUrl = "~/secure/nteg/default.aspx";            
            menunws.Text = "NWS";
            menunws.NavigateUrl = "~/secure/nws/default.aspx";
            menupfo.Text = "PFO";
            menupfo.NavigateUrl = "~/secure/pfo/default.aspx";
            menuqa.Text = "QA";
            menuqa.NavigateUrl = "~/secure/qa/default.aspx";
            menuqwest.Text = "QWest";
            menuqwest.NavigateUrl = "~/secure/qwest/default.aspx";
            menureports.Text = "Reports";
            menureports.NavigateUrl = "~/secure/reports/default.aspx";
            menuroamex.Text = "RoamEx";
            menuroamex.NavigateUrl = "~/secure/roamex/default.aspx";
            menusocial.Text = "Social";
            menusocial.NavigateUrl = "~/secure/social/default.aspx";
            menutt.Text = "Trouble Tickets";
            menutt.NavigateUrl = "~/secure/tt/default.aspx";

            MenuItemCollection menucollect = new MenuItemCollection();
            menucollect.Add(menuadmin);
            menucollect.Add(menuasc);
            menucollect.Add(menucpni);
            menucollect.Add(menugu);
            menucollect.Add(menuimports);
            menucollect.Add(menuinsight);
            menucollect.Add(menunteg);            
            menucollect.Add(menunws);
            menucollect.Add(menupfo);
            menucollect.Add(menuqa);
            menucollect.Add(menuqwest);
            menucollect.Add(menureports);
            menucollect.Add(menuroamex);
            menucollect.Add(menusocial);
            menucollect.Add(menutt);

            return menucollect;

Open in new window

woodjeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
You just need to hold a reference to the parent item and add to its ChildItems collection:

MenuItem menu = new MenuItem("Top-Level");

menu.ChildItems.Add(new MenuItem("Child 1"));
menu.ChildItems.Add(new MenuItem("Child 2"));

Open in new window

0
AsishRajCommented:
or
'parent
Dim item As New MenuItem
item.Text  = something
Menu1.Items.Add(item)

'child
Menu1.Items(0).ChildItems.Add(item)
0
AsishRajCommented:
Refer below article. It gives a good explanation plus example for your reference regarding Adding Menu Items Programmatically.

http://authors.aspalliance.com/aspxtreme/webforms/controls/addingmenuitemsprogrammatically.aspx 
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

woodjeAuthor Commented:
Carl tawn,

Thanks for the quick response. I have added your code and I now see the sub menu items but how do I set the text and the NavigateUrl?
0
AsishRajCommented:
i thought you will have that issue and that is the reason i gave that URL for further info.

ANyway hope this helps



MenuItem parentMenuItem= new MenuItem ( menuitemText, menuItemValue );
parentMenuItem.NavigateUrl = webPageUrl;
menuObject.Items.Add ( parentMenuItem);

MenuItem newItem = new MenuItem ( menuitemText, menuItemValue );
newItem.NavigateUrl = webPageUrl;
parentMenuItemObject.ChildItems.Add ( newItem );

Open in new window

0
Carl TawnSystems and Integration DeveloperCommented:
The same way you would with a top-level item. Simply keep a hold of the reference to the new child item and set the required properties before adding it to the collection:
MenuItem menu = new MenuItem("Top-Level");
MenuItem child;

child = new MenuItem("Child 1");
child.NavigateUrl = "somewhere.aspx";
menu.ChildItems.Add(child);

child = new MenuItem("Child 2");
child.NavigateUrl = "somewhereelse.aspx";
menu.ChildItems.Add(child);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AsishRajCommented:
@carl_tawn

better explanation and example then i provided.
0
woodjeAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.