?
Solved

Adding menu items ASP.net 2.0

Posted on 2007-08-12
1
Medium Priority
?
153 Views
Last Modified: 2013-11-26
Hello, I'm new to menus and I need it to populate off of my database table "Categories". I'm getting an error that says "cannot cast string to menu item". Here's my code:
Dim omenuCategory As Menu = New Menu()
omenuCategory = mpContentPlaceHolder.FindControl("menuCategory")
        While (readerCategories.Read())
            omenuCategory.Items.Add(readerCategories.GetValue(0))
        End While
"Categories" is a nvarchar. I'm afraid I'm not doing it right and my books seem insufficient, does anyone have some sample code for adding categories and sub-menu items?
0
Comment
Question by:jumpstart0321
1 Comment
 
LVL 8

Accepted Solution

by:
davecorun earned 2000 total points
ID: 19680852
You need to programatically create a MenuItem first, and then add that to the menu.

See the below link and sample code, they should help you a lot.

http://msdn2.microsoft.com/en-us/library/sk7kk6a5.aspx


 ' Create the root menu item.
      Dim homeMenuItem As New MenuItem("Home")

      ' Create the submenu items.
      Dim musicSubMenuItem As New MenuItem("Music")
      Dim moviesSubMenuItem As New MenuItem("Movies")

      ' Add the submenu items to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(musicSubMenuItem)
      homeMenuItem.ChildItems.Add(moviesSubMenuItem)

      ' Add the root menu item to the Items collection
      ' of the Menu control.
      NavigationMenu.Items.Add(homeMenuItem)
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question