View Full Version : Asp and tables

01-17-2003, 06:23 PM
I have my page pulling from a database. I would like my table rows to alternate between grey and white. I haven't seen any code on this. I didn't know if I just use a loop and where. Any help would be great. I would also like to add a page set so only 10-15 items come in on a page similar to the board.

01-17-2003, 06:57 PM
This is how you can implement different colors for odd and even rows - if you would like to group it otherwise you can develop the script further.

set rs = conn.Execute(sSQL)

i = 0
Do While Not rs.EOF
If i = 0 Then
sColor = "#FFFFFF"
i = 1
sColor = "#C0C0C0"
i = 0
End If
Response.Write "<tr><td bgcolor=" & sColor & ">TEXT</td></tr>"

01-17-2003, 07:00 PM
And if you wan't to implement page listing you can look at http://www.aspfaq.com/show.asp?id=2120


01-18-2003, 01:03 AM
Same thing, slightly different method:

Dim i, colorarray
i = 0
colorarray = Split("#ffffff,#cccccc",",")
Response.Write("<table>" & vbCrLf)
Do While Not rs.EOF
Response.Write("<tr><td bgcolor=" & colorarray(i) & ">TEXT</td></tr>" & vbCrLf)
i = ((i + 1) MOD 2)
Response.Write("</table>" & vbCrLf)

01-20-2003, 08:41 PM
I must be doing something wrong...
I have 2 pages. The page I am changing is this..

<!-- #include file="includes/common.asp" -->

ProcessPage True, "Welcome to the Catalog"

sub Main()
Dim iCategoryID, oRS
iCategoryID = Request.Querystring("CategoryID")
set oRS = getRecordset("SELECT * FROM tblItems WHERE intCategoryID = " & iCategoryID& " ORDER BY vchName;")
if (oRS.BOF AND oRS.EOF) Then
Response.write "Sorry, there are no products in this category. Please select another.<P>"
response.write "<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=2>" & vbCrLf
Do While NOT oRS.EOF
ShowItemDetails oRS
Response.Write "</TABLE>" & vbCrLf
End If

end sub

Here is the showdetails ors page that gets called:

sub ShowItemDetails(oRS)
dim x


<td width="75%" colspan="3"><b>&nbsp;<% =oRS("vchName")%>&nbsp;<b>
<% if oRS("vchImageName") ="" then %>
<% Response.Write "<font color=red><i>No image!</font>" & vbCrLf%>
<% end if %>
<% if oRS("vchImageName") <>"" then%>
<a href="javascript: popUpimg('Test.asp?img=<% =oRS("vchImageName")%>','popup','340','375','0');void(0);"><img src="images/camera.gif" border=0></A>
<% end if %></b></i></td>

<tr><td colspan=3><i><% =oRS("vchYear")%>&nbsp;<%=oRS("vchTeam")%>&nbsp;<% =oRS("vchType")%></i></td></tr>
<tr><td width="350" colspan="3"><%=oRS("vchDescription")%></td></tr>
<tr><td width="50%"></td><td width="75%"></td><td width="40%"><% if oRS("intCardNumber") ="" then%><% response.write("card #")%><%=oRS("intCardNumber")%><%end if%></td></tr>
<tr><td width="10%"></td><td width="10%"></td><td width="40%" rowspan="2"></td></tr>

<tr><td colspan=3 width="40%" valign="top">
<table><tr><td>Price: <B><% =formatcurrency(oRS("monPrice"))%> </b></td><td>
<% if oRS("intInventory") = "0" then
Response.Write "<font color=red><i>This item is out of stock.</i></font>" & vbCrLf
else %>
<form method="GET" action="cart.asp">
<input type="hidden" name="action" value="add">
<input type="hidden" name="intItemID" value="<%=oRS("intItemID")%>">
<p><select size="1" name="count">
<% for x = 1 to CInt(oRS("intInventory"))
Response.write"<option value=" & x & ">" & x & "</option>" & vbCrLf
next %>
<td><input type="image" value="Submit" name="B1" src="images/buy.GIF" border=0 onclick="popUp()"> </p>
<input type="hidden" name="intInventory" value="<%=CInt(oRS("intInventory"))%>">
<input type="hidden" name="ReturnURL" value="<%= "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("PATH_INFO") & "?" & Request.ServerVariables("QUERY_STRING") %>">
<% end if %>

<tr><td colspan=3><p>&nbsp;<p></td></tr>
end sub

I figured part of the code goes in each page. I don't get any errors it just changes every row to the same color??

01-21-2003, 01:13 AM
Yikes... fyi, there's a nice little forum feature you can use to make your code easier to read when you post... use this:

' Code here

I would attempt to reformat your code in order to be able to make sense of it, but I have too many other things going on. :)

Hint: That looks like a mess because the formatting was lost - can you repost the code with the formatting intact? ;)