Solved

Adding to a child Menu element in code

Posted on 2010-09-11
2
278 Views
Last Modified: 2012-05-10
Good morning,
Ive been struggeling with this for a while, and thought Id try experts-exchange.

Ive put a MenuControl on my page, which I have I have a menu Item called 'Accounts', then a child menu item 'Accounts List', which I need to be able to create a list of accounts, with a href.

So for example, add child menu items such as 'Alliance and Leicester' with a hyperlink of showTransactions.aspx?Account=1, then another one such as 'Barcelys' with a hyperlink of showTransactions.aspx?Account=2.

Ive searched google for 'asp.net MenuItem adding elements in code', but havnt found anything.

Any ideas how I can code these elements in code?

Thank you
0
Comment
Question by:tonelm54
2 Comments
 
LVL 10

Accepted Solution

by:
krunal_shah earned 500 total points
ID: 33652716
0
 

Author Comment

by:tonelm54
ID: 33652810
Just for anyone else who is looking for this:-



                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal" PathSeparator=",">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Accounts" Value="Accounts">
                            <asp:MenuItem Text="Accounts" Value="Account List"></asp:MenuItem>
                            <asp:MenuItem Text="Modify Accounts" Value="Modify Accounts"></asp:MenuItem>
                            <asp:MenuItem Text="Reports" Value="Reports"></asp:MenuItem>
                        </asp:MenuItem>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="Documents" Value="Documents"/>
                    </Items>
                </asp:Menu>
 
 
    Sub loadNodes()
        Dim item As MenuItem = NavigationMenu.FindItem("Accounts,Account List")
 
        item.ChildItems.Add(newMenuItem("Alliance and Leicter", "viewTransactions.aspx?account=1"))
        item.ChildItems.Add(newMenuItem("Natwest", "viewTransactions.aspx?account=2"))
        item.ChildItems.Add(newMenuItem("Barcleys", "viewTransactions.aspx?account=3"))
        item.ChildItems.Add(newMenuItem("Lloyds", "viewTransactions.aspx?account=4"))
    End Sub
 
    Function newMenuItem(ByVal strText As String, ByVal strNavigate As String) As MenuItem
        Dim newItem As New MenuItem
        newItem.Text = strText
        newItem.NavigateUrl = strNavigate
        newItem.Value = strText
 
        Return newItem
    End Function
 
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

10 Experts available now in Live!

Get 1:1 Help Now