Solved

Adding to a child Menu element in code

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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