Click to See Complete Forum and Search --> : alternating CSS styles when returning a RS


jjr0319
07-27-2005, 02:15 PM
im creating an ASP page with Access as the backend (don't laugh). anyway, i want to display a set of records in a particular table. it's working fine, but i want each subsequent record to have a different CSS style so it's easier to read and distinguish between records. here's what i have working so far:

<%
Dim rs
Dim strSQL
Dim curr
Dim outstring
Dim header
Dim spacer
spacer = " "
datetrail=""


Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=d:\inetpub\wwwroot\subs\testcfms\actlogs.mdb;User

Id=admin;Password=;"
conn.Open

strSQL = strSQL & "SELECT ARMY.[REQUESTED_BY], "
strSQL = strSQL & "ARMY.[REQUESTED_OF], "
strSQL = strSQL & "ARMY.[MILITARY_SERVICE], "
strSQL = strSQL & "ARMY.[SUBJECT_TOPIC], "
strSQL = strSQL & "ARMY.[STATUS], "
strSQL = strSQL & "ARMY.[COMMENTS] "




strSQL = strSQL & "FROM ARMY"



Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic


if rs.BOF and rs.EOF then

response.write "<b>Click on your browser's <b><I>Back</I></B> button to return to the input page."
else

Do While Not rs.EOF
by= rs("REQUESTED_BY")
of= rs("REQUESTED_OF")
service=rs("MILITARY_SERVICE")
subject=rs("SUBJECT_TOPIC")
status=rs("STATUS")
comm=rs("COMMENTS")

%>

<tr>
<td align="left" valign="top" class="????????" width="45%"><b>Date of Request:</b>
<br><b>Due Date:</b>
<br><b>Requested By:</b> <%= by %>
<br><b>Requested Of:</b> <%= of %>
<br><b>Military Service:</b> <%= service %>
<br><b>Subject/Topic:</b> <%= subject %>
<br><b>Status:</b> <font color="#33CC00"><%= status %></font>
<br><b>Follow Up Date:</b>
</td>
</tr>

<%
rs.MoveNext
Loop
End if

rs.Close
conn.Close
Set objRecordset = Nothing
Set objConnection = Nothing
%>

i want the each record <tr> to alternate between class="tabledkblue2" and class="tablegray2".

any help would be greatly appreciated.
thanks in advance.

schizo
07-27-2005, 03:54 PM
There are a lot of ways to do this. One way would be to track the current rs count and determine if the number is even/odd using the mod % and assign a class accordingly.

However, the most rudimentary way would be to do something like this would be...

...
' delcare default class name
Dim str_class = "odd"

Do While Not rs.EOF
by= rs("REQUESTED_BY")
of= rs("REQUESTED_OF")
service=rs("MILITARY_SERVICE")
subject=rs("SUBJECT_TOPIC")
status=rs("STATUS")
comm=rs("COMMENTS")

%>

<tr>
<td align="left" valign="top" class="<%=str_class%>" width="45%"><b>Date of Request:</b>
<br><b>Due Date:</b>
<br><b>Requested By:</b> <%= by %>
<br><b>Requested Of:</b> <%= of %>
<br><b>Military Service:</b> <%= service %>
<br><b>Subject/Topic:</b> <%= subject %>
<br><b>Status:</b> <font color="#33CC00"><%= status %></font>
<br><b>Follow Up Date:</b>
</td>
</tr>

<%
' toggle class name
If str_class = "odd" Then
str_class = "even"
Else
str_class = "odd"
End If


rs.MoveNext
Loop
End if
...

lmf232s
07-27-2005, 04:26 PM
just adding to what schizo said in there being multiple ways.
Here is another

Dim i

Do while not objRS.EOF
if i Mod 2 then
sColor = "MyCSSClassName"
else
sCOlor = "MyOtherCSSClassName"
end if

<tr class="<%=sColor%>">

</tr>

i = i + 1

objRS.MoveNext
Loop
%>

jjr0319
07-27-2005, 04:36 PM
works perfect. appreciate the help.
thanks again.