Solved

Adding to a child Menu element in code

Posted on 2010-09-11
2
282 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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