Click here to Skip to main content
6,630,901 members and growing! (19,293 online)
Email Password   helpLost your password?
Web Development » ASP » Components     Advanced

ASP TreeList Control (Requires Internet Explorer 5.0+)

By Nathan Ridley

An ASP class (Classic ASP) that generates a dynamic html tree list control that looks the same as a windows explorer tree but allows multiple columns of data per tree node
.NET 1.0, Win2K, WinXP, ASP, Dev
Posted:21 Apr 2002
Views:194,038
Bookmarked:71 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
25 votes for this article.
Popularity: 6.29 Rating: 4.50 out of 5
2 votes, 10.5%
1

2

3
4 votes, 21.1%
4
13 votes, 68.4%
5

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


Member
Web application developer, graphic designer, aspiring entrepreneur, snowboarder and electronic music afficianado.


Occupation: Web Developer
Location: Australia Australia

Other popular ASP articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 63 (Total in Forum: 63) (Refresh)FirstPrevNext
Generallimited nodes to the treecontrollist ? Pinmemberced4pass4:12 28 Jul '05  
Generalwhy not render with XSL Pinmemberlyredsoft9:53 22 Apr '05  
GeneralColumn resizing does not work In IE 6.0 PinsussLilya22:55 29 Mar '05  
Generalhow can I add new node? Pinmemberalexeom19:10 4 Dec '03  
Generalchild without parent PinmemberEraserR0:52 24 Nov '03  
GeneralShow all tree elements Pinmembersohhh16:29 30 Sep '03  
GeneralRe: Show all tree elements PinmemberNathan Ridley16:51 30 Sep '03  
GeneralRe: Show all tree elements Pinmembersohhh7:51 1 Oct '03  
GeneralASP.NET? PinmemberOBRon17:45 29 Jul '03  
GeneralRe: ASP.NET? PinmemberNathan Ridley18:00 1 Aug '03  
GeneralTREELISTCONTROL VERSION 3.0 PinmemberNathan Ridley12:23 23 Apr '03  
GeneralRe: TREELISTCONTROL VERSION 3.0 Pinmembernteller11:06 8 Jun '03  
Generali need help in use this code to display tree folder Pinmemberbmwmpowers23:28 22 Apr '03  
GeneralRe: i need help in use this code to display tree folder PinmemberNathan Ridley12:21 23 Apr '03  
GeneralRe: i need help in use this code to display tree folder PinsussAnonymous5:54 24 Apr '03  
GeneralRe: i need help in use this code to display tree folder PinmemberNathan Ridley15:26 26 Apr '03  
GeneralMAC Explorer 5.0+ PinsussBelse7:27 30 Jan '03  
GeneralRe: MAC Explorer 5.0+ PinmemberNathan Ridley11:19 30 Jan '03  
GeneralMuch faster way of expanding nodes PinsussAnonymous6:53 29 Dec '02  
GeneralRe: Much faster way of expanding nodes PinsussAnonymous13:26 29 Dec '02  
GeneralRe: Much faster way of expanding nodes Pinmembery109137:25 30 May '03  
GeneralRe: Much faster way of expanding nodes Pinmembermgcristino0:28 14 Sep '04  
GeneralGenerate treeview in html page PinmemberJob520:46 3 Dec '02  
GeneralRe: Generate treeview in html page Pinmemberx_sjb19:00 17 Feb '03  
GeneralRe: Generate treeview in html page PinmemberNathan Ridley10:28 18 Feb '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Apr 2002
Editor: Cameron Grant
Copyright 2002 by Nathan Ridley
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project