Troubleshooting the Simple Ajax Treeview

Posted on 2009-06-30
Last Modified: 2012-08-14
Hi experts,

I downloaded some sample code to create a treeview using ajax and sql but I'm having difficulties getting it to work with my tables. I'm getting the error of a blank page. I downloaded the sample code from
I ran the query in the analyzer and it produced good results when i swapped out my userID for intParentId. I can't figure for the life of me where the origional parentId (mentorID) comes from in this script. Please look at the code to help me figure out what I'm doing wrong. Thanks!
Class TreeView
Private m_strMenuTable
Private m_strIdField
Private m_strParentIDField
Private m_strTextField
Private m_strConn
Public Property Let MenuTable(vNewValue): m_strMenuTable = vNewValue: End Property
Public Property Let IdField(vNewValue): m_strIdField = vNewValue: End Property
Public Property Let ParentIDField(vNewValue): m_strParentIdField = vNewValue: End Property
Public Property Let TextField(vNewValue): m_strTextField = vNewValue: End Property
Public Property Let ConnectionString(vNewValue): m_strConn = vNewValue: End Property
Private Sub Class_Initialize
	m_strMenuTable = "dbo.Members"
	m_strIdField = "userID"
	m_strParentIDField = "mentorID"
	m_strTextField = "lastName" & "," & "firstName"
End Sub
Private Sub Class_Terminate
	'Clear Objects 
End Sub
Public Function GetChildNodes(intParentId)
	Dim strSQL
	strSQL = "SELECT " & _
	m_strIdField & "," & _
	m_strTextField & "," & _
	"(SELECT COUNT(*) FROM " & m_strMenuTable & " B WHERE A."& m_strIdField &"=B." & m_strParentIDField & ") AS [HasChild]" & _
	" FROM " & m_strMenuTable &" A "& _
	" WHERE " & m_strParentIDField & " = " & intParentId
	Const strXsl = "treeview.xsl"
	GetChildNodes = GetDbXml(m_strConn,strSQL, strXsl)
End Function
Private Function GetDbXml(strConn,strSQL,strXsl)
	Dim strXml
	'test strsql
	strXml = GetDbString(strConn,strSql,"__COL","__ROW","__NULL")
	strXml = Replace(strXml,"&","&amp;")
	strXml = Replace(strXml,"<","&lt;")
	strXml = Replace(strXml,"__COL","</col><col>")
	strXml = Replace(strXml,"__ROW","</col></row><row><col>")
	strXml = Replace(strXml,"__NULL","")	
	strXml = "<rows><row><col>" & strXml & "</col></row></rows>"			
	strXml = Replace(strXml,"<row><col></col></row>","")
	If strXsl <> "" Then		
		Dim xml,xsl
		'Load XML
		if not loadXmlDoc(xml,strXml,"GetDb XML Source") then exit Function
		if not loadXmlDoc(xsl,strXsl,"GetDb XSL Stylesheet") then exit Function
		'Transform file
		strXml = xml.transformNode(xsl)
		Set xml = Nothing
		Set xsl = Nothing
	End If
	GetDbXml = strXml        	
End Function 
Private Function GetDbString(strConn,strSQL, ColumnDelimiter, RowDelimiter, NullExpr)
	Dim Conn 
	Set Conn = Server.CreateObject("ADODB.Connection")
	Conn.Open strConn
	Dim RS
	Set RS = Conn.Execute(strSql)		
	If Not RS.EOF Then		
		GetDbString = RS.GetString(,, ColumnDelimiter, RowDelimiter, NullExpr) 
	End If	
	Set RS = Nothing
	Set Conn = Nothing					
End function
Private Function LoadXmlDoc(ByRef xmldoc, ByVal source, ByVal title)
	If Trim(source) = "" Then
		Exit Function
	End If
	Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
	If Left(source,7) = "http://" Then
		xmldoc.setProperty "ServerHTTPRequest", True
		xmldoc.async =  False
		'set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
		xmldoc.async = false
		If InStr(source,"<") Then 
			if InStr(source,":\") = 0 then source = Server.MapPath(source)
			'test source
		end if
	End If
	if xmldoc.parseError.errorcode <> 0 then
		'"<error code='" & xmldoc.parseError.errorcode & "'><![CDATA[" & xmldoc.parseError.reason & "]]></error>"
		LoadXmlDoc = True
	end if		
End Function
End Class
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
	<xsl:output method="xml" indent="no" omit-xml-declaration="yes" />
	<xsl:variable name="images.folder" select="'images'" />	
	<xsl:template match="/">		
			<xsl:apply-templates  />
	<xsl:template match="row">
		<xsl:variable name="" select="col[1]" />
		<xsl:variable name="text" select="col[2]" />
		<xsl:variable name="has.child" select="col[3]" />
		<table border="0" cellpadding="0" cellspacing="0">
				<td rowspan="2" width="10" valign="top">
					<img id="I{$}">
							<xsl:when test="number($has.child) &gt; 0">
								<xsl:attribute name="src">
									<xsl:value-of select="concat($images.folder,'/plus.gif')"/>
								<xsl:attribute name="onclick">
									<xsl:value-of select="concat('loadItems(',$,')')"/>
								<xsl:attribute name="src">
									<xsl:value-of select="concat($images.folder,'/dot.gif')"/>
				<td nowrap="true">
					<a href="javascript:alert({$});">
						<xsl:value-of select="$text" />						
				<td id="C{$}" style="display:none;"></td>
// global request and XML document objects
var req;
// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {	
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;"GET", url, true);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        //isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
  "GET", url, true);
// handle onreadystatechange event of req object
function processReqChange(){
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {		
			// ...processing statements go here...
			response  = req.responseXML.documentElement;
			method =
			//result = response.getElementsByTagName('result')[0];
			var start = req.responseText.indexOf('<result>') + 8
			var stop = req.responseText.indexOf('</result>')
			result = req.responseText.substring(start,stop);
			eval(method + '(\'\', result)');
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
var current_el = null;
var loading;
var began = false      
function getItems(input, response){	
	if (response != ''){ 		
	    // Response mode	
        current_el.innerHTML = response; = 'none'
		// Input mode			
		var url  = "process_request.asp?p=" + input + "&hash=" + Math.random();
function loadItems(id,c){ 
	var img = null;
		c = "C" + id;
		img = document.getElementById("I"+id);
	current_el = document.getElementById(c);
	if( == 'none'){ = ''
		if(img)img.src = "images/minus.gif";
	}else{ = 'none'
		if(img)img.src = "images/plus.gif";
	if(current_el.innerHTML == ''){ = ''
function buildTree(id){
	if (!began){
		loading = document.getElementById("Loading")
		document.getElementById(id).style.display = 'none';
		began = true;
<%Option Explicit%>
<!--#include file="treeview.asp"-->
Sub GetItems(parentId)
	Dim strConn,strTable
	strTable = "dbo.Members"
	strConn = "Provider=sqloledb; Data; Initial Catalog=xxx; User ID=xxx; Password=xxx"
	Dim tv
	Set tv = New TreeView
	tv.MenuTable = strTable
	tv.ConnectionString = strConn
	Response.Write tv.GetChildNodes(MM_userID)
	Set tv = Nothing
End Sub
Dim parentId:parentId = Request("p") 
If parentId="" Then parentId = 0
Response.ContentType = "text/xml"
<%= "<?xml version='1.0' encoding='ISO-8859-1'  standalone='yes'?>" %>
  <result><% Call GetItems(parentId) %></result>

Open in new window

Question by:GMMC_man
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 29

Accepted Solution

Badotz earned 500 total points
ID: 24745864
This is not a question, it is an expression of need for application development, and for those kinds of needs you should hire a developer.

We are not paid to do development here at EE -- we are just volunteers who answer questions for points and the occasional T-shirt.

Perhaps Rent-A-Coder or a similar service can help you.

Best of luck with your project.

Author Comment

ID: 24746733
Ok - thanks.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question