Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 4th, 2004, 04:25 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default What do I have to do ? Can you help me !

I have an ASP. it like
<%
Dim Cn
Dim Rs
Cn=Server.CreateObject("ADODB.Connection")
Cn=Server.CreateObject("ADODB.Recordset")
Cn.Open ("DSN=Database")
Rs.Open "Select * from MyTableName",Cn,1,2
%>
<Table>
       <Tr>
             <Td>Field name 1</Td>
             <Td>Field name 2</Td>

       </Tr>
<%Do Until Rs.EOF%>

<Tr>
           <Td><%=Rs("fieldname1")%></Td>
           <Td><%=Rs("fieldname2")%></Td>

</Tr>
<%Rs.MoveNext%>
<%Loop%>

</Table>

It has no bug . But what I want is: The background of the table change depend on the Recordset

Ex: The background of the First Recordset is black and The Second is White and
    The third is black and 4th is white and more until Rs.EOF


Thank for your help



  #2 (permalink)  
Old May 4th, 2004, 07:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Is this color a field of the recordset (Rs("Color")), or could you make it? The only other way is to check the position that the recordset is at, and based on that set the td tag to contain the color as such:

<td color='<%=strColor%>'>

You can check the current record and based on the value use an if or select statement to version, or store the color in the recordset by appending it to the query.

Brian
  #3 (permalink)  
Old May 4th, 2004, 07:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I forgot to mention that the property is the AbsolutePosition property that denotes the current record.
  #4 (permalink)  
Old May 4th, 2004, 07:30 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Alternatively, you can set up a simple loop counter and use the Mod operator to determine the color:
Code:
<%
  Dim BackGroundColor
  Dim LoopCount
  LoopCount = 0

  Do Until Rs.EOF
  If LoopCount Mod 2 = 0 Then
    BackGroundColor = "#00ff00"
  Else
    BackGroundColor = "#cc6666"
  End If
%>
<tr style="background-color:<%=BackGroundColor%>">
  <td><%=Rs("fieldname1")%></td>
  <td><%=Rs("fieldname2")%></td>
</tr>
<%
  Rs.MoveNext
  LoopCount = LoopCount + 1
  Loop
%>
This code will alternate the rows by looking at LoopCount. If LoopCount divided by 2 does not leave a remainder, the color #00ff00 is used, otherwise #cc6666 is used.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Regen En Patchoulli by Spinvis (Track 13 from the album: Spinvis) What's This?






Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.