Adding menu items 2.0

Posted on 2007-08-12
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())
        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?
Question by:jumpstart0321
    1 Comment
    LVL 8

    Accepted Solution

    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.

     ' 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.

          ' Add the root menu item to the Items collection
          ' of the Menu control.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now