Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview populated from database

Status
Not open for further replies.

walderr

Programmer
Jul 18, 2003
32
GB
Hi,

I'm trying to set up a treeview function which is populated via a database. I've got a script for the treeview, and I can sort of populate it with values from the database, but it's nowhere near right!

The section which needs the work done (as far as I can tell) is below, and the problem comes when trying to loop around the recordset- I've put stars around the loop function just so you can see it. I've tried putting the loop in various places, but it always comes up with an error referring to the javascript located above it, which controls the tree, saying that part of it is null. At this point, it runs partway through the script, populating some of the fields (sometimes it manages to run further than others, it seems to be random). If anyone could either point out where my looping has gone wrong, or direct me to a script with a similar example, that would be great. Here's the section as it stands:

<%
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objConn.Open (&quot;Vendor&quot;)
sqltext = &quot;SELECT Equipment.[ID Number] FROM Equipment;&quot;
objRS.CursorLocation = 3 'adUseClient as opposed to adUseServer - use server would return -1
objRS.Open sqltext, objConn

WriteHead &quot;TreeView&quot;,1,&quot;Tanks&quot;,0,True,False,&quot;&quot;,True
**************While Not objRS.EOF**************
WriteHead &quot;TreeView&quot;,2,objRS(&quot;ID Number&quot;),1,True,False,&quot;&quot;,False
WriteHead &quot;TreeView&quot;,3,&quot;A&quot;,2,False,False,&quot;&quot;,False
WriteFoot
WriteHead &quot;TreeView&quot;,4,&quot;B&quot;,2,False,False,&quot;&quot;,False
WriteFoot
WriteHead &quot;TreeView&quot;,5,&quot;C&quot;,2,False,False,&quot;&quot;,False
WriteFoot
WriteFoot
**************objRS.Movenext**************
**************Wend**************


objRS.Close
objConn.Close
Set objConn = Nothing
%>

 
I used this script for something many moons ago. Here is an example that works down to 3 levels. From this you should be able to figure out how it works:

Code:
<form name=&quot;frmSummary&quot; method=&quot;post&quot; action=&quot;<%=request.servervariables(&quot;SCRIPT_NAME&quot;)%>&quot;>
<%strSql=&quot;SELECT GoalID,GoalTitle,Comp_Description,DueDate FROM vw_Goal_Competency WHERE EmpID=&quot; & lEmpID
set rsGoal = conn.execute(strSql)
If not rsGoal.eof then
	Counter = 0
	Counter2 = 1
	Counter3 = 2
	do while not rsGoal.eof
		GoalID = rsGoal(&quot;GoalID&quot;)
		Goal = rsGoal(&quot;GoalTitle&quot;)
		Competency = rsGoal(&quot;Comp_Description&quot;)
		DueDate = rsGoal(&quot;DueDate&quot;)
		Counter = Counter + 1
		TreeName = &quot;Tree&quot; & Counter
		WriteHead TreeName,Counter,Goal & &quot;<br> -- Due Date: &quot; & DueDate & &quot;<br> -- Competency: &quot; & Competency,0,TRUE,FALSE,&quot;&quot;,False
			strSql = &quot;SELECT ActivityID, Activity FRom tbl_d_Activity WHERE GOALID =&quot; & GoalID
			set rsAct = conn.execute(strSql)
				IF not rsAct.eof then
					Do while not rsAct.eof
						ActivityID=rsAct(&quot;ActivityID&quot;)
						Activity = rsAct(&quot;Activity&quot;)
						Counter=Counter+1
						WriteHead TreeName,Counter,Activity,1,TRUE,FALSE,&quot;&quot;,FALSE
							strSql = &quot;Select TaskID,Task,DueDate,Complete FROM tbl_d_Task WHERE ActivityID = &quot; & ActivityID
							set rsTask= conn.execute(strSql)
							if not rsTask.eof then
								do while not rsTask.eof
									TaskID = rsTask(&quot;TaskID&quot;)
									Task = rsTask(&quot;Task&quot;)
									dDueDate = rsTask(&quot;DueDate&quot;)
									if rsTask(&quot;Complete&quot;) = FALSE then
										strStatus = &quot;Incomplete&quot;
									else
										strStatus = &quot;Complete&quot;
									end if
									counter=counter+1
									If strStatus = &quot;Complete&quot; THEN
									WriteHead TreeName,Counter,Task & &quot; -- Due Date: &quot; & dDueDate & &quot; -- Status: &quot; & strStatus,2,FALSE,FALSE,&quot;&quot;,FALSE
									ELSE
									WriteHead TreeName,Counter,Task & &quot; -- Due Date: &quot; & dDueDate & &quot; -- Status: &quot; & strStatus,2,FALSE,FALSE,&quot;NewTracker.asp?GoalID=&quot; & GoalID & &quot;&TaskID=&quot; & TaskID,FALSE
									END IF
									WriteFoot
									rsTask.movenext
								loop
							End if
							set rsTask=Nothing
						WriteFoot
						rsAct.movenext
					Loop
				End if
				Set rsAct = Nothing
		WriteFoot
		rsGoal.movenext
		Loop
		Set rsGoal=Nothing
ELSE
response.write &quot;<div align='center'><font color='red'><b>No Records</b></font></div>&quot;		
End if	
%>
</form>[code]
 
I want to do something similar but I don't know how many levels are going to be used as the db is still growing. Anyone know how to do this?

Cheers
lbob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top