SoFunction
Updated on 2025-03-10

Make a table with alternating row background color changes under asp

<%
Const adInteger = 3
Const adVarChar = 200 
' Declare variables
Dim myRecordset 
Dim iLetter     
Dim Field       
Dim strAltColor 
Dim bColor      
bColor = False

' This example uses the recordset in memory. All you need to do is modify the part of your data display.
Set myRecordset = ("")
 "ID", adInteger
 "Title", adVarChar, 25
 "Description", adVarChar, 255



' Fill RS with sample data:
For iLetter = Asc("A") To Asc("M")
 
 ("ID").Value          = iLetter - 64
("Title").Value       = "Letter:" & Chr(iLetter)
("Description").Value = "The letters tested here: " & Chr(iLetter) & ".
 
Next 'iLetter

'Move to the head start position so that the following loop begins.



' Show data in the table

 "<table border=""0"" cellspacing=""0"" cellpadding=""3"">" & vbCrLf

'Check header
 vbTab & "<tr>" & vbCrLf
For Each Field in 
  vbTab & vbTab & "<td bgcolor=""#CCCCCC""><strong>"
  
  "</strong></td>" & vbCrLf
Next 'Field
 vbTab & "</tr>" & vbCrLf

Do While Not 
'Loop to change the background color of the cell
 bColor = Not bColor
 If bColor Then
  strAltColor = "#FFFFFF"
 Else
  strAltColor = "#FF8040"
 End If

'Loop to change the background color of the cell
  vbTab & "<tr>" & vbCrLf
 For Each Field in 
   vbTab & vbTab & "<td bgcolor="""
   strAltColor
   """>" &  & "</td>" & vbCrLf
 Next 'Field
  vbTab & "</tr>" & vbCrLf

 
Loop

' End the table
 "</table>" & vbCrLf

' Close the object and release the resource

Set myRecordset = Nothing
%>