Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > ASP.NET 2.0 TreeView (expand on click of text)?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-10-2006, 03:01 AM
mcdonnc2004's Avatar
mcdonnc2004 mcdonnc2004 is offline
Junior Contributor
 
Join Date: Dec 2003
Location: Liverpool, UK
Posts: 276
Default ASP.NET 2.0 TreeView (expand on click of text)?


I am playing about with the two menu systems in VWD trying to create the best one for non-savvy users. I think the simplicity of the TreeView control is ideal but the one thing that would throw users is only being able to click on the arrows at the side to expand the menu!

Is there a way to get the TreeView to expand by clicking on the parent node text as well as the arrow?

Also, it would be nice if open nodes closed when you clicked on a different node. Currently, you can expand all nodes which can take up a lot of space. Can an open node collapse automatically when a different node is clicked? I cannot find a property that would do this.

Thanks.
Reply With Quote
  #2  
Old 05-10-2006, 07:35 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

I didn't see any properties to get what you're looking for automatically either. One option would be to take a look at what is generated by the code, and create a new class that inherits from the existing node class. Then you can make it clickable.

You could also probably add the appropriate javaScript to close the open node, but I'm not sure the easiest place to add it. But again, I'd do it in an inherited class.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 05-11-2006, 02:40 AM
mcdonnc2004's Avatar
mcdonnc2004 mcdonnc2004 is offline
Junior Contributor
 
Join Date: Dec 2003
Location: Liverpool, UK
Posts: 276
Default

I was afraid that would be the answer! I'm rubbish with Javascript but I'll give it a go. Thanks wayneph.
Reply With Quote
  #4  
Old 05-11-2006, 07:21 AM
mcdonnc2004's Avatar
mcdonnc2004 mcdonnc2004 is offline
Junior Contributor
 
Join Date: Dec 2003
Location: Liverpool, UK
Posts: 276
Default

Ok, I tried with the client side code but I am really bad with Javascript so I went back to client side coding and managed to get this working:

Code:
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) For Each tn As TreeNode In TreeView1.Nodes If tn.Value <> e.Node.Value Then tn.Collapse() End If Next End Sub

I set the SelectAction of the TreeView to SelectExpand and that works. I can click on the text to make it expand and with the code above it will collapse all open nodes except the one I'm on but it posts back to the server each time you expand!

Does anyone know of a way through Javascript to acheive what I need? The part I can figure out on my own is that maybe I need to point the URL of each parent node to a Javascript function and within this function provide the code that can expand/collapse nodes when the text is clicked.

Its the actual code for this function that I really cannot do!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->