Click here to Skip to main content
Click here to Skip to main content

ASP TreeList Control (Requires Internet Explorer 5.0+)

By , 21 Apr 2002
 

Sample Image - asptreelistcontrol.gif

Introduction

I needed a class to create a tree list control for a web application I'm building, and after looking around on the net and failing to find anything similar, I decided to create my own. The main challenge with creating a decent tree list control with HTML, CSS and JScript is that there is no way to effectively create a node heirarchy and guarantee that the columns for each node will line up with the columns for all the other nodes. I experimented with div, span, table, tbody, thead, tr, p, ul, etc, but none offered an acceptable solution.

My solution was to create a single non-heirarchical table and store all of the node information in a javascript array. When a +/- button is pressed, the javascript extrapolates from the array which rows it has to hide and which nodes it has to show. Note that doing it this way I also had to store state information for every expandable node so that when expanding or collapsing a node, it would maintain the expanded/collapsed state of child nodes.

The ASP class generates an initial tree and the JScript code reads the html and extracts the information it needs to make the tree interactive. Unfortunately you can't update the tree with the current code once it has been generated in the browser, but that is ok because I had no need to do that.

My MAIN issue with this tree list control is, although it is reasonably fast to generate, and works perfectly, after you get about 100-200 nodes in the tree (I'm using a Pentium 4, 1.4ghz), the JScript starts getting very slow and unresponsive. If you find this control useful and manage to optimise the jscript code so that it is actually fast with a large number of nodes in the tree, I would greatly appreciate it if you could post the updated code here so I can take a look.

Below is the code to create a demonstration tree list. As you can see the control is very easy to use, just create an instance of the control, add the column headings, and then add the nodes. You can't add a node if its parent doesn't yet exist. Also, you should not reveal a node using the reveal function unless the node actually exists. Doing so will cause the page to create an error.

<!--#include file="treelistcontrol/treelistcontrol.asp"-->
<%
	dim tree
	set tree = new treelistcontrol

	'specify our default settings for the tree
	tree.allowrowselect = false
	tree.showborder = false
	tree.pathtoicons = "treelistcontrol/"
	tree.showdividers = false

	'define the columns for the tree
	tree.addcolumn "Node Name", "", ""
	tree.addcolumn "Day of Week", "100", ""
	tree.addcolumn "Month", "100", ""
	tree.addcolumn "Random Number", "80", "right"
	
	dim id, parentid, theday, themonth, thenumber
	randomize
	for id = 1 to 100
		'make some random values for the tree
		parentid = int(rnd*id)
		theday = weekdayname(int(rnd*7)+1)
		themonth = monthname(int(rnd*12)+1)
		thenumber = formatnumber(int(rnd*1000000),,,true)
		
		'add the node
		tree.addnode id+0, parentid, "treelistcontrol/icon_folder.gif", false, _
				array(id+0, theday, themonth, thenumber)
		
	next
	'reveal node #100
	tree.revealnode 100
	
	response.write tree.value
%>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nathan Ridley
Web Developer
Australia Australia
Member
Web application developer, graphic designer, aspiring entrepreneur, snowboarder and electronic music afficianado.
 

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHi , This is very nice treelist controlmemberomid136123 Feb '10 - 7:16 
i like this control , this is very good . are you develop this control in asp.net ??
AnswerRe: Hi , This is very nice treelist controlmemberNathan Ridley23 Feb '10 - 7:19 
Umm, heh I did this control 8 years ago. It was for classic ASP and was built to target IE5 and IE6. I wouldn't use it today at all; instead I'd build something with jQuery and to support modern browser standards. IE6 probably wouldn't even make the cut, depending on the target audience.
Questionlimited nodes to the treecontrollist ?memberced4pass28 Jul '05 - 3:12 
I'd like to know how to extend the number of nodes in the tree list ?
True, for a large number of entries, I get the message "impossible to find the page"
When I reduce the number of entries in the xml file manually then it's fine.

Generalwhy not render with XSLmemberlyredsoft22 Apr '05 - 8:53 
very nice,but i think you can render with xsl, i have meet a russian boy's xml tree,more excellent!
GeneralColumn resizing does not work In IE 6.0sussLilya29 Mar '05 - 21:55 
After upgrading IE to version 6 with service pack 1 "resizing columns" option
does not function anymore. Any ideas ?
 
Thanks,
Lilya
Questionhow can I add new node?memberalexeom4 Dec '03 - 18:10 
how can I add/delete node?
and how can I display selected folder's items?
 
plz ^^
 
from alexeom
Generalchild without parentmemberEraserR23 Nov '03 - 23:52 
Is is possible to implement feature that will skip child entries if no parent is available?
GeneralShow all tree elementsmembersohhh30 Sep '03 - 15:29 
Sorry to ask about the OLD version of the tree, but is it possible to show all child nodes with a single click (or start will all displayed)?
 
Thanks for your help and for the great example.
GeneralRe: Show all tree elementsmemberNathan Ridley30 Sep '03 - 15:51 
The answer to your question is in the addnode function. I *think* it's parameter #3, but have a look to be sure.
 
NATHAN RIDLEY
Web Application Developer
generalgherkin@yahoo.com
GeneralRe: Show all tree elementsmembersohhh1 Oct '03 - 6:51 
Worked great. My mistake was that I was not using "true" for the root node.
 
Thanks again for the help and script.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 22 Apr 2002
Article Copyright 2002 by Nathan Ridley
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid