Display Alternating Background Colors in Search Results from Access:
Code:
list.asp
Highlight
<% Dim conn, rs, strconn, DBQValue, bgcolor set conn = server.createobject("adodb.connection") set rs = server.createobject("adodb.recordset") conn.open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & server.mappath("DATABASE NAME.mdb") strsql = "select * from TABLE OR QUERY NAME where" If Request.Form("Name") <> "" Then strsql = strsql & " Name = '" &_ Request.Form("Name") & "' and " End If If Request.Form("Division") <> "" Then strsql = strsql & " Division = '" & _ Request.Form("Division") & "' and " End If strsql=left(strsql,(len(strsql) - 5)) rs.open strsql,conn, 2, 2 bgColor="#CCCCCC" %>
<%If rs.BOF and rs.EOF Then response.redirect "search.asp?Results=False" Else%> <%If Not rs.BOF Then%>
Search Results:
Name
Division
<%do while not rs.EOF if bgColor="#CCCCCC" then bgcolor="#E5E5E5" else bgColor="#CCCCCC" end if%>
valign=top> <%=rs("Name")%>
valign=top> <%=rs("Division")%>
">Details...
<% rs.MoveNext loop %>
<%End If%> <%End If%>
<% rs.close conn.close set rs = nothing set conn = nothing %>