Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2010 VB.NET Treeview , +
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:
     

     
    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 6-Jun-12 8:45am
    Edited 6-Jun-12 11:06am
    Nelek51.3K
    v5
    Comments
    SAKryukov at 6-Jun-12 14:56pm
       
    Format fixed: removed HTML-enticized "> <" and redundant "pre"
    --SA
    Nelek at 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
    good
    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.
     
    http://pushpontech.blogspot.co.uk/2007/06/client-side-expandcollapse-all-nodes.html[^]
      Permalink  
    Comments
    Member 3491662 at 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 at 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 at 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 at 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: <!--
     
    -->
     
    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
    0 Sergey Alexandrovich Kryukov 901
    1 OriginalGriff 445
    2 CPallini 255
    3 Richard Deeming 175
    4 George Jonsson 161
    0 OriginalGriff 5,540
    1 Sergey Alexandrovich Kryukov 4,668
    2 CPallini 4,540
    3 George Jonsson 3,102
    4 Gihan Liyanage 2,445


    Advertise | Privacy | Mobile
    Web03 | 2.8.140916.1 | Last Updated 6 Jun 2012
    Copyright © CodeProject, 1999-2014
    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