Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Greetings,

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:


    VB
    Protected Sub TreeView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DataBound
            TreeView1.CollapseAll()
            Dim tn As TreeNode = TreeView1.SelectedNode
            tn.Expand()
            If tn.Parent IsNot Nothing Then
                tn = tn.Parent
                tn.Expand()
            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
    Updated 6-Jun-12 11:06am
    v5
    Comments
    Sergey Alexandrovich Kryukov 6-Jun-12 14:56pm    
    Format fixed: removed HTML-enticized "> <" and redundant "pre"
    --SA
    Nelek 6-Jun-12 17:11pm    
    the code tags were HTML-encoded you had [pre lang = "& quot;vb & quot;"]. fixed to "vb"

    1 solution

    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.

    http://pushpontech.blogspot.co.uk/2007/06/client-side-expandcollapse-all-nodes.html[^]
     
    Share this answer
     
    Comments
    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    
    Hmm...

    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)



    CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900