Wrox Home  
Search P2P Archive for: Go

's

  Return to Index  

asp_web_howto thread: write recordset rows in alternating bgcolor

Message #1 by "Dave Wray" <threeflush@h...> on Thu, 13 Sep 2001 22:20:01
What's an easy way to write the contents of a recordset into alternating 

colored rows while looping through that recordset?



html would look like:



<tr bgcolor=black>

   <td> ...recordset data..</td>

</tr>

<tr bgcolor=white>

   <td> ...more RS data...</td>

</tr>

 

etc......
Message #2 by Greg Griffiths <griffiths@x...> on Thu, 13 Sep 2001 23:04:17 +0100
theCol="white"

Do While Not results.EOF



         Response.Write("<tr>")

         Response.Write("<td bgcolor='"& theCol &"'>" & results("name") & 

"</td>")

         Response.Write("</tr>")



         if (theCol="white") then

                 theCol="#CCCCCC"

         else

                 theCol="white"

         end if



         results.movenext

loop



At 22:20 13/09/01 +0000, you wrote:

>What's an easy way to write the contents of a recordset into alternating

>colored rows while looping through that recordset?

>

>html would look like:

>

><tr bgcolor=black>

>    <td> ...recordset data..</td>

></tr>

><tr bgcolor=white>

>    <td> ...more RS data...</td>

></tr>

>

>etc......
Message #3 by "phil griffiths" <pgtips@m...> on Fri, 14 Sep 2001 09:18:38
keep a count as you're going thro the records and use the Mod function to 

determine bg colour, e.g. If count Mod 2 = 0 then ColourA else ColourB



> What's an easy way to write the contents of a recordset into alternating 

> colored rows while looping through that recordset?

> 

> html would look like:

> 

> <tr bgcolor=black>

>    <td> ...recordset data..</td>

> </tr>

> <tr bgcolor=white>

>    <td> ...more RS data...</td>

> </tr>

>  

> etc......
Message #4 by "Drew, Ron" <RDrew@B...> on Fri, 14 Sep 2001 09:06:14 -0400
...Alternating Colors...

'loop

 counter=counter+1

 response.write "<TR bgcolor="""

   IF counter mod2=0 THEN

      response.write "#000000"

   ELSE

      response.write "#FFFFFF"

   END IF

 response.write """><TD>recordset data</TD></TR>"

'end loop



-----Original Message-----

From: Dave Wray [mailto:threeflush@h...]

Sent: Thursday, September 13, 2001 6:20 PM

To: ASP Web HowTo

Subject: [asp_web_howto] write recordset rows in alternating bgcolor

<tr>'s





What's an easy way to write the contents of a recordset into alternating 

colored rows while looping through that recordset?



html would look like:



<tr bgcolor=black>

   <td> ...recordset data..</td>

</tr>

<tr bgcolor=white>

   <td> ...more RS data...</td>

</tr>

 

etc......
Message #5 by Tarey Gettys <tareyg@y...> on Fri, 14 Sep 2001 08:14:19 -0700 (PDT)
What if you are using XML data islands? Is there a way

to alternate the row colors?

Tarey

--- phil griffiths <pgtips@m...> wrote:

> keep a count as you're going thro the records and

> use the Mod function to 

> determine bg colour, e.g. If count Mod 2 = 0 then

> ColourA else ColourB

> 

> > What's an easy way to write the contents of a

> recordset into alternating 

> > colored rows while looping through that recordset?

> > 

> > html would look like:

> > 

> > <tr bgcolor=black>

> >    <td> ...recordset data..</td>

> > </tr>

> > <tr bgcolor=white>

> >    <td> ...more RS data...</td>

> > </tr>

> >  

> > etc......

>

Message #6 by Shaun Steckley <SSTECKLEY@P...> on Fri, 14 Sep 2001 11:18:36 -0400
What I do is keep an integer counter while looping...



i = 0

Do while not rs.eof

   If (i Mod 2 = 0) Then                   ' - used to alter the BG color of

the table row

      m_Response.Write "  <tr bgcolor=""black"">" & vbCrLf

   Else

      m_Response.Write "  <tr bgcolor=""white"">" & vbCrLf

   End If



   i = i + 1



   print out other values in td tags...

loop



-----Original Message-----

From: Dave Wray [mailto:threeflush@h...]

Sent: Thursday, September 13, 2001 6:20 PM

To: ASP Web HowTo

Subject: [asp_web_howto] write recordset rows in alternating bgcolor

<tr>'s





What's an easy way to write the contents of a recordset into alternating 

colored rows while looping through that recordset?



html would look like:



<tr bgcolor=black>

   <td> ...recordset data..</td>

</tr>

<tr bgcolor=white>

   <td> ...more RS data...</td>

</tr>

 

etc......



Message #7 by "Bailey, Mark" <MBailey@m...> on Fri, 14 Sep 2001 11:29:16 -0400
I do this using xslt.



e.g.)

	

	<!-- figure out colour based on row nuber -->

	<xsl:variable name="colour">

	<xsl:choose>

		<xsl:when test="position() mod 2=0">black</xsl:when>

		<xsl:otherwise>white</xsl:otherwise>

	</xsl:choose>

	</xsl:variable>



	<!-- create the row using the given colour-->

	<tr bgColor="{$colour}" height="25">

		<xsl:apply-templates />

	</tr>



You transform the data island using this xslt, and display the output.

Of course if you haven't used xslt there is a lot to learn before trying

this.



-----Original Message-----

From: Tarey Gettys [mailto:tareyg@y...]

Sent: Friday, September 14, 2001 11:14 AM

To: ASP Web HowTo

Subject: [asp_web_howto] Re: write recordset rows in alternating bgcolor

<tr>'s





What if you are using XML data islands? Is there a way

to alternate the row colors?

Tarey

--- phil griffiths <pgtips@m...> wrote:

> keep a count as you're going thro the records and

> use the Mod function to 

> determine bg colour, e.g. If count Mod 2 = 0 then

> ColourA else ColourB

> 

> > What's an easy way to write the contents of a

> recordset into alternating 

> > colored rows while looping through that recordset?

> > 

> > html would look like:

> > 

> > <tr bgcolor=black>

> >    <td> ...recordset data..</td>

> > </tr>

> > <tr bgcolor=white>

> >    <td> ...more RS data...</td>

> > </tr>

> >  

> > etc......

>


  Return to Index