CodeAve.com CodeAve.com - ASP - Database Table Display
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Alternating Table Color
Adding alternating colors to your output data is a great way to help "dress-up" your output.  By adding a simple counter in our output loop, reading the last digit of that counter's value and selecting a color based on that integer we're able to alternate the table cells background color.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<html>
<title>CodeAve.com(Table Colors)</title>
<body bgcolor="#FFFFFF">
<%
' Name of the Accessdb being read
accessdb="fidrych"

' Connect to the db with a DSN-less connection
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

' Select all data from the table the_bird
sql = "select * from the_bird "

' Execute the sql
rs.Open sql, cn
%>


<table BORDER="0" CELLPADDING="0" CELLSPACING="0" align="center" width="640">
<caption>Mark <i>The Bird</i> Fidrych Career Stats</caption>
<tr>
<td>Year</td>
<td>Team</td>
<td>W</td>
<td>L</td>
<td>G</td>
<td>GS</td>
<td>CG</td>
<td>IP</td>
<td>H</td>
<td>BB</td>
<td>SO</td>
<td>ShO</td>
<td>ERA</td>
</tr>

<%
' Move to the first record
rs.movefirst

' Start a loop that will end with the last record
do while not rs.eof

' Simple counter that adds one for each observation in the record set
count=count + 1

' Looks for the last digit in the count variable
i_last=right(count,1)

' If the last digit of the variable count is an odd number
' then make the background green
select case i_last
case "1","3","5","7","9"
bgcolor = "#C0E4C6"

' If not make the background white
case else
bgcolor = "#FFFFFF"
end select
%>



<tr bgcolor="<%= bgcolor%>">
<td>
<%= rs("year") %>
</td>

<td>
<%= rs("team") %>
</td>

<td>
<%= rs("w") %>
</td>

<td>
<%= rs("l") %>
</td>

<td>
<%= rs("g") %>
</td>

<td>
<%= rs("gs") %>
</td>

<td>
<%= rs("cg") %>
</td>

<td>
<%= rs("ip") %>
</td>

<td>
<%= rs("h") %>
</td>

<td>
<%= rs("bb") %>
</td>

<td>
<%= rs("so") %>
</td>

<td>
<%= rs("sho") %>
</td>

<td>
<%= rs("era") %>
</td>
</tr>

<%
' Move to the next record
rs.movenext
' Loop back to the do statement
loop %>

</table>

</body>
</html>
<%
' Close and set the recordset to nothing
rs.close
set rs=nothing
%>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3