Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Alternating Table Colors
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Alternating Table Colors

 Post Reply Post Reply
Author
kennywhite View Drop Down
Groupie
Groupie


Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
Post Options Post Options   Thanks (0) Thanks(0)   Quote kennywhite Quote  Post ReplyReply Direct Link To This Post Topic: Alternating Table Colors
    Posted: 02 March 2009 at 7:05pm
Hello,
 
I looked online for a few examples of how to do this, but I've not been able to find anything that doesn't break my page or simply doesn't work at all. Can anyone tell me how to properly do this? I'd like for every other 
<tr>
tag to be a different color.
 
Here is my code currently:
 

 
<html>
<head>
<title>Assets</title>
</head>
<body bgcolor="white" text="black">
<table cellspacing="0" cellpadding="0" border="1" width="100%">
<tr>
<th align="center" width="150" bgcolor="gray"><b><u>DEVICE TYPE</U></B></th>
<th align="center" width="100"  bgcolor="gray"><b><u>MODEL #</U></B></th>
<th align="center" width="150"  bgcolor="gray"><b><u>SERIAL #</U></B></th>
<th align="center" width="150"  bgcolor="gray"><b><u>DEPARTMENT</U></B></th>
<th align="center" width="150"  bgcolor="gray"><b><u>USER</U></B></tdh>
<th align="center" width="110"  bgcolor="gray"><b><u>CONDITION</U></B></th>
<th align="center" width="250"  bgcolor="gray"><b><u>NOTES</U></B></th></TR>
<%
'Dimension variables
Dim adoCon         'Holds the Database Connection Object
Dim rsAsset    'Holds the recordset for the records in the database
Dim strSQL         'Holds the SQL query to query the database
 
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

 'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("assets.mdb")
 'Create an ADO recordset object
Set rsAsset = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database DESCending order
strSQL = "SELECT assets.DeviceType, assets.Model, assets.Serial, assets.Department, assets.User, assets.Condition, assets.Notes FROM assets ORDER BY assets.ID_no DESC;"
 
 

'Open the recordset with the SQL query
rsAsset.Open strSQL, adoCon
%>
 

<%
'Loop through the recordset
Do While not rsAsset.EOF
    'Write the HTML to display the current record in the recordset
 
Response.Write ("<tr>")
Response.Write ("<td>")   
    Response.Write (rsAsset("DeviceType"))
Response.Write ("</td>")
Response.Write ("<td>")
    Response.Write (rsAsset("Model"))
Response.Write ("</td>")
Response.Write ("<td>")
Response.Write (rsAsset("Serial"))
Response.Write ("</td>")
Response.Write ("<td>")
Response.Write (rsAsset("Department"))
Response.Write ("</td>")
Response.Write ("<td>")
Response.Write (rsAsset("User"))
Response.Write ("</td>")
Response.Write ("<td>")
Response.Write (rsAsset("Condition"))
Response.Write ("</td>")
Response.Write ("<td>")
    Response.Write (rsAsset("Notes"))
Response.Write ("</td>")
Response.Write ("</tr>")
 
    'Move to the next record in the recordset
    rsAsset.MoveNext
Loop
 
'Reset server objects
rsAsset.Close
Set rsAsset = Nothing
Set adoCon = Nothing
%>
</table>
</body>
</html>
 
 
 
Thanks in advance!
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 02 March 2009 at 8:29pm
Add at the start of the loop:

Do While not rsAsset.EOF 

if iLoop = 2 then iLoop = 0

if iLoop = 1 then
   strColour = "#99999"
else
  strColour = "#EEEEE"
end if



add to the row

Response.Write ("<tr bgcolor=""" & strColour & """>")



Add at the end of the loop

    iLoop = iLoop + 1

    rsAsset.MoveNext
Loop



You can easily change it to CSS if you wish.
S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
kennywhite View Drop Down
Groupie
Groupie


Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
Post Options Post Options   Thanks (0) Thanks(0)   Quote kennywhite Quote  Post ReplyReply Direct Link To This Post Posted: 03 March 2009 at 2:17pm
Thumbs Up
 
THANKS!
 
This is by far the most helpful forum I've ever joined!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.