Question

Expand Treeview childnodes by clicking on parent node text

Asked by: donaldef

I am using a sitemap with a treeview that is 3 levels deep.  The treeview is embedded in a master page.  The treeview is set to show 2 levels by default. The user can click on the expansion node indicator to view the third level (childnodes) for that area.   However, I would like for the user to click on the parent node text (next to the expansion node indicator) to view the child nodes.  

In the example below, clicking on the "Message Center" text would show the URL for that selection and also show the childnodes of "View Messages" and "Create Messages". Any help would be appreciated.

> Home

      >> Message Center
            >>> View Messages
            >>> Create Message
      
      >> Account
            >>> Update Profile
            >>> Update Password
            >>> Update Billing


I have had difficulty with 1) looping through the childnodes of the selected parent and 2) expanding the childnodes during the loop process.  Nothing that I am trying seems to work.  I have been putting my code in the master page code behind.

Please note that I am using VB NET.  

           <asp:TreeView ID="TreeView1" runat="server" 
                DataSourceId="nav1" 
                Nodeindent="10" 
                ShowExpandCollapse="true" 
                ExpandDepth="2"
                Imageset="Arrows" 
                EnableViewState="true"
                PopulateNodesFromClient="False"   >
                <LevelStyles>
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Bold="true" 
                        Font-Size="10pt"
                        ForeColor="black" />
                    <asp:TreeNodeStyle 
                        ChildNodesPadding="5" 
                        Font-Bold="true"
                        Font-Size="10pt" 
                        ForeColor="black" />
                    <asp:TreeNodeStyle  
                        ChildNodesPadding="5"
                        Font-Size="10pt" 
                        ForeColor="DarkBlue" /> 
                    <asp:TreeNodeStyle  
                        ChildNodesPadding="5"
                        Font-Size="8pt" 
                        ForeColor="darkred" />                     
                </LevelStyles>
                <ParentNodeStyle 
                    Font-Bold="False" 
                    ForeColor="Black" />
                <HoverNodeStyle 
                    Font-Underline="True" 
                    ForeColor="#5555DD" />
                <SelectedNodeStyle 
                    Font-Underline="True" 
                    ForeColor="#5555DD" 
                    HorizontalPadding="0px" 
                    VerticalPadding="0px" />
                <RootNodeStyle 
                    ForeColor="Black" />
                <NodeStyle 
                    Font-Names="Verdana" 
                    Font-Size="8pt" 
                    ForeColor="Black" 
                    HorizontalPadding="0px" 
                    NodeSpacing="0px" 
                    VerticalPadding="0px" />
            </asp:TreeView>
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-25 at 10:55:08ID24680750
Tags

Web Development Treeview VB NET

Topics

Microsoft Visual Basic.Net

,

.NET

,

Programming for ASP.NET

Participating Experts
1
Points
500
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Please help with recursive count of childnodes in a TreeView
    I'm trying to click on a node of a treeview and get a count of all nodes below it and throughout any sub levels of the hierachy. I'm finding this difficult because of the way in which child nodes are 'modelled' with the TreeView component. Why each child is not an item of a...
  2. Add childnode in a treeview
    Hi, I have a treeview. I want allow the user to add a new items anywhere in the tree. How can I do that ? I mean, the user select a node, click a button, add the informations and click OK. Then the information is add in a new node, child of the one he select previously. ...
  3. Listview with childnodes like treeview
    Hi there, Is it possible to make a listview displaying collapsed / expanded listitems, like in a treeview? I don't want all the items to be collapsable, and the collapsable items need only one level of childnodes, so i don't want to have the childnodes collapsable too.. ...
  4. childNode
    There doesn't seem to be a .childNode function built into javascript. So, what is the easiest way to access child elements? If I have a <div>, and I want to access a child <img>, is there a simple way to do this? (I don't want to access it directly, via getEl...
  5. Populating Childnodes in treeviews
    I have 2 tables Table appCategories CategoryName (PK) Table appReports ReportName (PK) ParentCategory (FK) so each category has a bunch of reports that belong to it What I want to do is populate a treeview so the categories are all parent nodes, that expand to their c...
  6. Sorting a Treeview's ChildNodes
    Hi, I have a simple TreeView that I populate at run-time. All the nodes are added programmatically so there is nothing at design time other than the TreeView control itself. All my Parent Notes are fine and all my Child Nodes load fine as well, except for one thing. The Chil...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: guru_samiPosted on 2009-08-27 at 08:55:18ID: 25199670

Try TreeNodeDataBound Event...and set the SelectAction for your node like below:

protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
    {
        e.Node.SelectAction = TreeNodeSelectAction.SelectExpand;
        //Note there are different TreeNodeSelectAction for you to choose from
        //Set it according to your need
    }

 

by: guru_samiPosted on 2009-08-27 at 08:55:52ID: 25199676

VB.NET

Protected Sub TreeView1_TreeNodeDataBound(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
        'Note there are different TreeNodeSelectAction for you to choose from
        'Set it according to your need
    e.Node.SelectAction = TreeNodeSelectAction.SelectExpand
End Sub

 

by: donaldefPosted on 2009-08-27 at 09:18:37ID: 25199940

I copy/pasted the above VB Net code into the code behind for my master page code but it does not seem to be firing.   Recall that my treeview is located in my master page.

Is this master page code behind the wrong place to place the code?

 

by: guru_samiPosted on 2009-08-27 at 09:20:45ID: 25199967

may be you need to add ontreenodedatabound="TreeView1_TreeNodeDataBound" to your tV markup

or Handles treenodedatabound in your code-behind since it is VB ...

 

by: donaldefPosted on 2009-08-27 at 09:41:15ID: 25200186

Thanks, the code is now firing but expanding the childnodes by clicking on the parent node description text is still having no effect.  

I tried both e.Node.SelectAction = TreeNodeSelectAction.SelectExpand and e.Node.SelectAction = TreeNodeSelectAction.Expand.  

Again, I am clicking on the description next to the node, not the node itself.  Expanding the childnodes by clicking on the parent node works fine.

 

by: guru_samiPosted on 2009-08-27 at 09:54:57ID: 25200338

hmmm that code is working for me...
check sample below:

<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1"
        ExpandDepth="0" ontreenodedatabound="TreeView1_TreeNodeDataBound">
    </asp:TreeView>

CB..

protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
    {
        e.Node.SelectAction = TreeNodeSelectAction.SelectExpand;      
    }

--sitemap

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="" title="Home"  description="Home" roles="*">
    <siteMapNode url="" title="Admin"  description="" roles="*" >
      <siteMapNode url="" title="Default" description="" roles="admin" />
    </siteMapNode>
    <siteMapNode url="~/Test.aspx" title="Level 2"  description="" roles="*" />
    <siteMapNode url="" title="Users"  description="" roles="*" >
      <siteMapNode url="" title="Default" description="" roles="guest" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

 

by: guru_samiPosted on 2009-08-27 at 09:56:24ID: 25200352

oh yeah...you don't need those roles and stuff...it is just a sample sitemap which I used

 

by: donaldefPosted on 2009-08-27 at 10:20:21ID: 25200607

Sorry, I must be missing something obvious or possible not explaining well what I am trying to achieve.

Below are snippets of my code.  I am expecting to click on the text "Messages" in the second level of the site map and see the childnodes of "View Messages" and "Forums" which are on the 3rd level.  

I tried both e.Node.SelectAction = TreeNodeSelectAction.SelectExpand and e.Node.SelectAction = TreeNodeSelectAction.Expand with no apparent impact.  I know the code is firing because I see the looping during debug.

MASTER PAGE CODE BEHIND
Partial Class tnet_MasterPage
Inherits System.Web.UI.MasterPage
 
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
End Sub
		
Protected Sub TreeView1_TreeNodeDataBound(ByVal sender As Object, ByVal e As TreeNodeEventArgs) Handles TreeView1.TreeNodeDataBound
 
'Note there are different TreeNodeSelectAction for you to choose from
'Set it according to your need
e.Node.SelectAction = TreeNodeSelectAction.SelectExpand
 
End Sub
			
MASTER PAGE ASPX
<asp:SiteMapDataSource id="nav1" runat="server" /> 
<form id="form1" runat="server">		
<asp:TreeView ID="TreeView1" runat="server" DataSourceId="nav1" 
    Nodeindent="10" ShowExpandCollapse="true" 
    ExpandDepth="2"
    Imageset="Arrows" 
    EnableViewState="true"
    PopulateNodesFromClient="False" 
    ontreenodedatabound="TreeView1_TreeNodeDataBound" >
    <LevelStyles>
        <asp:TreeNodeStyle ChildNodesPadding="10" 
          Font-Bold="true" 
          Font-Size="10pt"
          ForeColor="black" />
        <asp:TreeNodeStyle 
          ChildNodesPadding="5" 
          Font-Bold="true"
          Font-Size="10pt" 
          ForeColor="black" />
        <asp:TreeNodeStyle  
          ChildNodesPadding="5"
          Font-Size="10pt" 
          ForeColor="DarkBlue" /> 
        <asp:TreeNodeStyle  
          ChildNodesPadding="5"
          Font-Size="8pt" 
          ForeColor="darkred" />                     
      </LevelStyles>
      <ParentNodeStyle 
          Font-Bold="False" 
          ForeColor="Black" />
       <HoverNodeStyle 
          Font-Underline="True" 
          ForeColor="#5555DD" />
       <SelectedNodeStyle 
          Font-Underline="True" 
          ForeColor="#5555DD" 
          HorizontalPadding="0px" 
          VerticalPadding="0px" />
        <RootNodeStyle 
          ForeColor="Black" />
        <NodeStyle 
          Font-Names="Verdana" 
          Font-Size="8pt" 
          ForeColor="Black" 
          HorizontalPadding="0px" 
          NodeSpacing="0px" 
          VerticalPadding="0px" />
       </asp:TreeView>
    </form>			
			
SITEMAP
	
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode title="Home" description="Home" url="~/tnet/home.aspx" roles="user" >
 
<siteMapNode title="My Learning" description="My Learning" myimage="test.jpg" url="~/tnet/mylearning.aspx" roles="user" >
 
<siteMapNode title="Message Center" description="Message Center" url="~/tnet/messagecenter/default.aspx" roles="user" >
 
<siteMapNode title="View Messages" description="View Messages" url="~/tnet/messagecenter/viewlist.aspx" roles="user" />
 
<siteMapNode title="View Forums" description="Discussion forums" url="~/tnet/messagecenter/forums.aspx" roles="user" />
</siteMapNode>
 
<siteMapNode title="Support" description="Support" url="~/tnet/Support.aspx" roles="user" />
		
<siteMapNode title="Logout" description="Logout" url="~/tnet/public/Logout.aspx" roles="user" />
 
	</siteMapNode>
 
</siteMap>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:

Select allOpen in new window

 

by: guru_samiPosted on 2009-08-27 at 10:35:22ID: 25200748

I see do you mean when you click on "Message Center" and navigate to url="~/tnet/messagecenter/default.aspx"
you want to expand the nodes on page .."~/tnet/messagecenter/default.aspx" ?

 

by: donaldefPosted on 2009-08-27 at 10:46:41ID: 25200855

I would like to expand the following childnodes when the "Message Center" text is clicked:

<siteMapNode title="View Messages" description="View Messages" url="~/tnet/messagecenter/viewlist.aspx" roles="user" />
 
<siteMapNode title="View Forums" description="Discussion forums" url="~/tnet/messagecenter/forums.aspx" roles="user" />

This allows the user to review the content of default.aspx but also see that there are two additional nodes they can click.  

Make sense?

 

by: guru_samiPosted on 2009-08-27 at 10:52:21ID: 25200909

yep that exactly what I meant in my last post....
but sorry I don't have a solution for that...but will update you if something strikes...

 

by: donaldefPosted on 2009-08-27 at 11:14:22ID: 25201081

The only thing that I can think to do is build a redirect into the "code behind" of the parent that redirects the user to an "overview" page located in the child area as follows:

CHILD NODES TO "MESSAGE CENTER"

<siteMapNode title="Overview" description="Overview" url="~/tnet/messagecenter/overview.aspx" roles="user" />

<siteMapNode title="View Messages" description="View Messages" url="~/tnet/messagecenter/viewlist.aspx" roles="user" />
 
<siteMapNode title="View Forums" description="Discussion forums" url="~/tnet/messagecenter/forums.aspx" roles="user" />

This method expands all that child menu of that area but seems sloppy.

 

by: donaldefPosted on 2009-08-27 at 12:33:01ID: 31620308

Definitely helped but was not the full answer I needed.  

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...