Important alert: (current site time 7/15/2013 10:55:39 PM EDT)
 

VB icon

Expanding Threads

Email
Submitted on: 1/29/2003 12:53:58 AM
By: Mark Leykamp 
Level: Beginner
User Rating: By 1 Users
Compatibility: ASP (Active Server Pages)
Views: 9634
 
     Some very easy logic to display expanding threads when the information comes from a database. It will anchor your place on the webpage and let you write more readable and larger webpages.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Expanding Threads
' Description:Some very easy logic to display expanding threads when the information comes from a database. It will anchor your place on the webpage and let you write more readable and larger webpages.
' By: Mark Leykamp
'
' Inputs:' my example uses a webpage named test.asp in a database with a table named tblTest that contains one text field of the information you want to show called test and a second text field called testing number that gives it a unique string that will associate the thread with the record number. my data is test
test	testing number
---	---
01	01a
01	01b
02	02a
02	02b
etc... until you have more records than screen
'
' Returns:a table with your chose record expanded
'
' Assumes:Prerequistes are knowing how to make am asp page with html tags that can connect to a database. there is no advanced anything.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8197&lngWId=4'for details.'**************************************

<%
'grab the requested record
varsubmit = request("lnksubmit")
'if there is not one yet just show the 
'first record
if varsubmit = "" then
varsubmit = 1
end if
'open your database connection
sDBName = "driver={Microsoft Access Driver (*.mdb)};dbq=YOURDATABASEHERE"
Set objDB = Server.CreateObject("ADODB.Connection")
objDB.Open sDBName
Set objRS = objDB.Execute("select * from tblTest")
'start the webpage here and rember to call 
'it test.asp
response.write("<form action=""test.asp"" method=POST>")
Response.Write("<html>")
Response.Write("<head>")
Response.Write("<title>Expanding Threads</title>")
Response.Write("</head>")
Response.write("<body>")
Response.Write("ASP Table Wizard")
'if we did not find anyrthing in the 
'database let the user know and close up
If objRS.EOF Then
	Response.Write("<b>No matching records found.</b>")
	objRS.Close
	objDB.Close
	Set objRS = Nothing
	Set objDB = Nothing
	Response.End
End If
'start the table and write the categories
Response.Write("<table border=0 cellpadding=2 cellspacing=2>")
Response.Write("<tr>")
Response.Write("<th>Testing</th>")
Response.Write("<th>Testing Number</th>")
Response.Write("<th>record Number</th>")
Response.Write("</tr>")
'keep looping through the database
Do While Not objRS.EOF
'grabs the database records into a variable 
'for manipulation
vartesting = objRS("Testing")
vartestingnumber = objRS("Testing Number")
'seperates the record number from the 
'thread number
'grabing the first 2 character for the record number 
testrecordnumber = mid(vartestingnumber, 1, 2)
'and the last character for the thread letter 
testthreadnumber = mid(vartestingnumber, 3, 1)
'start displaying the results
Response.Write("<tr">")
' if it is the first thread in a record or 
'the record you are looking for
if testthreadnumber = "a" or testrecordnumber = varsubmit then
'sub if it is the first thread in a 
'record and not the record you are 
'looking for
if testthreadnumber = "a" and testrecordnumber <> varsubmit then
'so this is the link to expand any first 
'thread exepct the record you already 
'have expanded
response.write("<td><a href=""" & request.ServerVariables("SCRIPT_NAME") & "?lnksubmit=" & testrecordnumber & "#" & vartestingnumber & """>+</a></td>")
else
'so this only runs the collapse link if 
'it is displaying the link you already chose 
'to expand
response.write("<td><a href=""" & request.ServerVariables("SCRIPT_NAME") & "?lnksubmit=0000001#" & vartestingnumber & """>-</a></td>")
end if
'this will only run and write the subthreads of 
'the record you are displaying 
Response.Write("<td>" & vartesting & "<a name=" & vartestingnumber & "> </a></td>")
Response.Write("<td>" & vartestingnumber & "</td>")
end if
Response.Write("</tr>")
'keep moving down the database
objRS.Movenext
loop
'and last of all finish up
Response.Write("</table>")
Response.Write("</body>")
Response.Write("</html>")
Response.Write("</form>")
objRS.Close
objDB.Close
Set objRS = Nothing
Set objDB = Nothing
%>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.