Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Re: write recordset rows in alternating bgcolor <tr>'s


Message #1 by "Rory Lysaght" <rory@g...> on Tue, 26 Nov 2002 00:38:54
I hope this thread hasn't gone cold, but I have a similar problem I'm 
trying to solve.

I'm doing a query (Access) that returns a recordset with a picture field 
and a text field.  The number of records per query varies, but all have 
these two fields. I want to create a two-column table where each record in 
the recordset takes up two table rows:
  --------------------
  | pic 1  |  pic 2  |
  --------------------
  | txt 1  |  txt 2  |
  --------------------
  | pic 3  |  pic 4  |
  --------------------
  | txt 3  |  txt 4  |
  --------------------

Since HTML can only write tables row by row, it seems I need to first go 
through two records, then somehow skip back two to write the second row, 
before going on to the next pair.  Am I making this too complicated, or is 
there a simpler way to achieve this?

Thanks,
  Rory


> 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 "Ken Schaefer" <ken@a...> on Tue, 26 Nov 2002 12:13:06 +1100
Use .GetRows()

<%
If not objRS.EOF then
    arrResults = objRS.GetRows
End If

' Close/Dispose of recordset object


' Assuming PictureURL is column 1, and text is column 2
' The following will write out the first two records:

If isArray(arrResults) then

    Response.Write("<tr>")
    Response.Write("<td>" & arrResults(0,0) & "</td>")
    Response.Write("<td>" & arrResults(0,1) & "</td>")
    Response.Write("</tr>")

    Response.Write("<tr>")
    Response.Write("<td>" & arrResults(1,0) & "</td>")
    Response.Write("<td>" & arrResults(1,1) & "</td>")
    Response.Write("</tr>")

Else

    Response.Write("No Records")

End If

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Rory Lysaght" <rory@g...>
Subject: [asp_web_howto] Re: write recordset rows in alternating bgcolor
<tr>'s


: I hope this thread hasn't gone cold, but I have a similar problem I'm
: trying to solve.
:
: I'm doing a query (Access) that returns a recordset with a picture field
: and a text field.  The number of records per query varies, but all have
: these two fields. I want to create a two-column table where each record in
: the recordset takes up two table rows:
:   --------------------
:   | pic 1  |  pic 2  |
:   --------------------
:   | txt 1  |  txt 2  |
:   --------------------
:   | pic 3  |  pic 4  |
:   --------------------
:   | txt 3  |  txt 4  |
:   --------------------
:
: Since HTML can only write tables row by row, it seems I need to first go
: through two records, then somehow skip back two to write the second row,
: before going on to the next pair.  Am I making this too complicated, or is
: there a simpler way to achieve this?
:
: Thanks,
:   Rory
:

Message #3 by "Ed Eddleman" <ed@e...> on Tue, 26 Nov 2002 08:58:11 -0500
This is the way I do it.

Do while not objRS.EOF
			if blnYN then
				blnYN=False
				response.Write("<tr bgcolor=#FAFAD2>...
			else
				blnYN=True
				response.Write("<tr>...
			end if
			objRS.MoveNext
	  	Loop

ed@e...

-----Original Message-----
From: Rory Lysaght [mailto:rory@g...]
Sent: Tuesday, November 26, 2002 12:39 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: write recordset rows in alternating bgcolor
<tr>'s


I hope this thread hasn't gone cold, but I have a similar problem I'm
trying to solve.

I'm doing a query (Access) that returns a recordset with a picture field
and a text field.  The number of records per query varies, but all have
these two fields. I want to create a two-column table where each record in
the recordset takes up two table rows:
  --------------------
  | pic 1  |  pic 2  |
  --------------------
  | txt 1  |  txt 2  |
  --------------------
  | pic 3  |  pic 4  |
  --------------------
  | txt 3  |  txt 4  |
  --------------------

Since HTML can only write tables row by row, it seems I need to first go
through two records, then somehow skip back two to write the second row,
before going on to the next pair.  Am I making this too complicated, or is
there a simpler way to achieve this?

Thanks,
  Rory


> 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