Alternating row color in a HTML table displaying r

Results 1 to 2 of 2

Thread: Alternating row color in a HTML table displaying r

  1. #1
    Dan Wick Guest

    Default Alternating row color in a HTML table displaying r

    I need a general approach on how to display database results in an HTML table where the row color alternates (i.e. white row, gray row, white row, gray row).<BR><BR>I completely understand how to write thte HTML to create the table with the rows, columns and change color within HTML. I&#039;m just looking for the ASP code to alternate the row color for recordset results.<BR><BR>Thanks,<BR>Dan

  2. #2
    Join Date
    Dec 1969

    Default Pretty trivial...

    Lots and lots of ways. The simplest:<BR><BR>&#060;%<BR>color = "white"<BR>Do Until RS.EOF<BR>&nbsp; &nbsp; Response.Write "&#060;TR bgColor=&#039;" & color & "&#039;&#062; ... <BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; If color = "white" Then color="lightgrey" Else color="white"<BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>A more general way, where you can have any number of colors that are used, in order:<BR><BR>&#060;%<BR>colors = Array("white","lightgrey","yellow","lightgreen","p ink")<BR><BR>counter = 0<BR>Do Until RS.EOF<BR>&nbsp; &nbsp; Response.Write "&#060;TR bgColor=&#039;" & colors(counter) & "&#039;&#062; ... <BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; counter = (counter + 1) <BR>&nbsp; &nbsp; If counter &#062; UBound(colors) Then counter = 0<BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>Or use a variation on that:<BR><BR>&#060;%<BR>colors = Array("white","lightgrey","yellow","lightgreen","p ink")<BR><BR>colorCount = UBound(colors)+1<BR>counter = 0<BR>Do Until RS.EOF<BR>&nbsp; &nbsp; Response.Write "&#060;TR bgColor=&#039;" & colors(counter MOD colorCount) & "&#039;&#062; ... <BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; counter = (counter + 1) <BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>Or dozens of other ways. Many, many that don&#039;t use an array, but I think the array simplifies things plus allows you to change your mind about which colors and number of colors just by changing the one line of code.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts