<%
Dim rstHighlight ' The recordset object
Dim objField ' Field looper for display
Dim blnColor ' Use for showing alternating colors
Dim strColor ' Temp string to hold current bgcolor
blnColor = True
' Create an instance of an ADO Recordset
Set rstHighlight = Server.CreateObject("ADODB.Recordset")
' Open our recordset. Since I don't need a connection object for
' anything else, I'm not creating one. I simply use the connection
' string that I would have used to open the connection to open the
' recordset instead.
rstHighlight.Open "SELECT * FROM scratch;", _
"Provider=SQLOLEDB;Data Source=10.2.2.133;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
' Start the table
Response.Write "<table border=""1"">" & vbCrLf
' Write Titles
Response.Write vbTab & "<tr>" & vbCrLf
For Each objField in rstHighlight.Fields
Response.Write vbTab & vbTab & "<td bgcolor=""#CCCCCC""><strong>"
Response.Write objField.Name
Response.Write "</strong></td>" & vbCrLf
Next 'objField
Response.Write vbTab & "</tr>" & vbCrLf
' Loop through records outputting data
Do While Not rstHighlight.EOF
' Alternate row color
blnColor = Not blnColor
If blnColor Then
strColor = "#CCCCFF" ' Light blueish
Else
strColor = "#FFFFFF" ' White
End If
' This is the line that enables the highlighting when you mouse
' over a table row. We use some simple client-side JavaScript
' to change the background color when we mouse over and change
' it back when the mouse moves back out.
Response.Write vbTab & "<tr bgcolor=""" & strColor & """ " _
& "onMouseOver=""this.bgColor='yellow'"" " _
& "onMouseOut=""this.bgColor='" & strColor & "'"">" & vbCrLf
' Loop over the fields showing the current record's data.
For Each objField in rstHighlight.Fields
Response.Write vbTab & vbTab & "<td>" & objField.Value & "</td>" & vbCrLf
Next 'objField
Response.Write vbTab & "</tr>" & vbCrLf
rstHighlight.MoveNext
Loop
' End the table
Response.Write "</table>" & vbCrLf
' Close and dispose of recordset object
rstHighlight.Close
Set rstHighlight = Nothing
%>
<p>
To see the highlighting in action, try mousing over the rows of the table.
</p>