ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

ASP Source Code:
' Select constants from want more info?  See:
Const adInteger = 3
Const adVarChar = 200
' Declare our vars
Dim myRecordset ' The recordset containing data to display
Dim iLetter     ' Letter looper to fill RS with sample data
Dim Field       ' Field looper for display so we don't need to know the names
Dim strAltColor ' To hold alternating color values
Dim bColor      ' Boolean we use to alternate colors
bColor = False
' Make up some sample data to display.  I'm using an in-memory recordset
' simply to keep things fast and because I assume most users will be using
' this script with some sort of database.  This way you should just be
' able to drop in your own DB code and edit the display section and you
' should have everything working pretty quickly.
Set myRecordset = Server.CreateObject("ADODB.Recordset")
myRecordset.Fields.Append "ID", adInteger
myRecordset.Fields.Append "Title", adVarChar, 25
myRecordset.Fields.Append "Description", adVarChar, 255
' Fill RS with sample data:
For iLetter = Asc("A") To Asc("M")
	myRecordset.Fields("ID").Value          = iLetter - 64
	myRecordset.Fields("Title").Value       = "The Letter " & Chr(iLetter)
	myRecordset.Fields("Description").Value = "This is an upper case " & Chr(iLetter) & "."
Next 'iLetter
' Move back to the beginning of the RS... as if we just opened it.
' Display the data in a table
' Start the table
Response.Write "<table border=""0"" cellspacing=""0"" cellpadding=""3"">" & vbCrLf
' Write Titles
Response.Write vbTab & "<tr>" & vbCrLf
For Each Field in myRecordset.Fields
	Response.Write vbTab & vbTab & "<td bgcolor=""#CCCCCC""><strong>"
	Response.Write Field.Name
	Response.Write "</strong></td>" & vbCrLf
Next 'Field
Response.Write vbTab & "</tr>" & vbCrLf
' Loop through records outputting data
Do While Not myRecordset.EOF
	' Toggle to the opposite color as the last row.
	bColor = Not bColor
	If bColor Then
		strAltColor = "#FFFFFF"  ' White
		strAltColor = "#DDFFDD"  ' Light green
	End If
	' You can use the alternating color contained in strAltColor
	' however you like... as text, row, or cell background or
	' foreground color.  I'm using it as cell background color here
	' for illustration, but the choice is all yours.
	Response.Write vbTab & "<tr>" & vbCrLf
	For Each Field in myRecordset.Fields
		Response.Write vbTab & vbTab & "<td bgcolor="""
		Response.Write strAltColor
		Response.Write """>" & Field.Value & "</td>" & vbCrLf
	Next 'Field
	Response.Write vbTab & "</tr>" & vbCrLf
' End the table
Response.Write "</table>" & vbCrLf
' Close and dispose of recordset object
Set myRecordset = Nothing

Back the the Sample Output

Back to the Sample Index

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers