Solved

Adding to a child Menu element in code

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 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

18 Experts available now in Live!

Get 1:1 Help Now