Click here to Skip to main content
13,291,084 members (67,399 online)
Rate this:
Please Sign up or sign in to vote.

I am currently working on our company's website that consists of two sets of navigational groups.

The first group is of course the main menu set to the left side of the page vertically, and the second group is the sub menu set on top of the page horizontally.

The main menu is using a TreeView control and the sub menu is setup in a simple "html"
    tag with the basic "html" link tags.

    I used the TreeView control because it gave me more functionality for expanding and collapsing the nodes when the user navigated throughout the web site.

    Actually I was able to search and find some code that would only expand the nodes depending on the parent node selected, and collapses the other nodes.

    Here is that code:

    Protected Sub TreeView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DataBound
            Dim tn As TreeNode = TreeView1.SelectedNode
            If tn.Parent IsNot Nothing Then
                tn = tn.Parent
            End If
        End Sub

    Now my problem is when the user selects a link in the sub menu it has a Null value. Is there a better way to do this when expanding the TreeView nodes. I must have a separate navigation menu different from the main menu? I do like how the main menu is working and did not want to change it. Any type of help would be really appreciative!

    Thank you
    Posted 6-Jun-12 9:45am
    Updated 6-Jun-12 12:06pm
    SAKryukov 6-Jun-12 14:56pm
    Format fixed: removed HTML-enticized "> <" and redundant "pre"
    Nelek 6-Jun-12 17:11pm
    the code tags were HTML-encoded you had [pre lang = "& quot;vb & quot;"]. fixed to "vb"

    1 solution

    Rate this: bad
    Please Sign up or sign in to vote.

    Solution 1

    If you were using ASP.NET link buttons you could use the TAG attribute to store the treeview parent node Id / name. On postback you could use the tag contents to work out what tree node to expand.

    If this is not the case then I think it would have to be some javascript. You could use the (if using a html a tag) rel attribute to store the parent node id in it. Knowing the id you could then raise an event to collaps and expand the nodes.[^]
    Member 3491662 7-Jun-12 14:00pm
    Thank you db7uk for responding back to me, but I am still a little lost.

    Are you saying if I change the Sub Menu to use a ASP Link Button(s) instead of using the 'a href' html tag that I could assign the ID and Text Name from the the Link Button's attributes back to the TreeView Parent?
    Member 3491662 7-Jun-12 15:46pm

    I hated to do this but I just added my sub menu links to my web.sitemap file without their title property but with just their url values. I have my sub menu still using html "a href" tags.

    I can see the huge gap between the rootnodes within the treeview. I think this is a very tacky way of making this work without completely undoing what I have accomplished so far.

    But I don't know what else to do? I am still open to other options if anyone has any suggestions.
    db7uk 7-Jun-12 16:04pm
    Hi, Sorry, just got your messages. So That I have a better picture, you have a tree view bound to a data source? This tree view is basically a view of all parent (main) links. Your sub menu is for say the second level menu nodes? Out of interest how is the sub menu being created? how are the links being added?
    Member 3491662 11-Jun-12 8:36am
    So That I have a better picture, you have a tree view bound to a data source?

    Yes... I have a tree view bound to a data source.

    Your sub menu is for say the second level menu nodes? Yes

    how are the links being added?

    In the web.sitemap file I have the following link for an example: <!--<SITEMAPNODE url="~/FindAgent/find_agent.aspx">


    Ok it is a little hard to show code here, but it is basically a sitemap node without its title attribute.

    In the mark-up I have the following for an example:/*<ul><li>Find Agent</li></ul>*/

    This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

      Print Answers RSS
    Top Experts
    Last 24hrsThis month

    Advertise | Privacy |
    Web02 | 2.8.171207.1 | Last Updated 6 Jun 2012
    Copyright © CodeProject, 1999-2017
    All Rights Reserved. Terms of Service
    Layout: fixed | fluid

    CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100