<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% ' Select constants from adovbs.inc... want more info? See: ' http://www.asp101.com/articles/john/adovbs/default.asp 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 myRecordset.Open ' Fill RS with sample data: For iLetter = Asc("A") To Asc("M") myRecordset.AddNew 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) & "." myRecordset.Update Next 'iLetter ' Move back to the beginning of the RS... as if we just opened it. myRecordset.MoveFirst ' Display the data in a table ' Start the table Response.Write "" & vbCrLf ' Write Titles Response.Write vbTab & "" & vbCrLf For Each Field in myRecordset.Fields Response.Write vbTab & vbTab & "" & vbCrLf Next 'Field Response.Write vbTab & "" & 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 Else 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 & "" & vbCrLf For Each Field in myRecordset.Fields Response.Write vbTab & vbTab & "" & vbCrLf Next 'Field Response.Write vbTab & "" & vbCrLf myRecordset.MoveNext Loop ' End the table Response.Write "
" Response.Write Field.Name Response.Write "
" & Field.Value & "
" & vbCrLf ' Close and dispose of recordset object myRecordset.Close Set myRecordset = Nothing %>