Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding color to Recordset

Status
Not open for further replies.

llldnylll

Technical User
May 21, 2003
89
Is there a way to add color to my Dynamic Text based on its data?


I have a page with all of items...
I want all record that contains the word tall to be blue, short yellow and med red.

Is it possible?



 
write a function...something like this:
Code:
Function colorRS(val)
Select Case val
 case "tall"
 colorRS = "<font color=""blue"">" & val & "</font>"
 case "short"
 colorRS = "<font color=""yellow"">" & val & "</font>"
 case "med"
 colorRS = "<font color=""red"">" & val & "</font>"
 case else
 colorRS = "<font color=""black"">" & val & "</font>"
End Select
End function

when you are displaying the recordset...call the function...

Code:
 colorRS(myrecordset("myfield"))

-DNG
 
It's possible but hard to answer your specific question without example data.

<.
 
Thanks for the response...

Where would I place colorRS(myrecordset("myfield"))?



Monksnake this is an example of the data:

Size Description Type Orderd
m T-shirt Team y
m Pants Plain n
m Shorts Team y
s T-shirt Team n
s Pants Plain y
s Shorts Team n
l T-shirt Team y
l Pants Plain n
l Shorts Team y
xl T-shirt Team n
xl Pants Plain y
xl Shorts Team n
other T-shirt Team y
other Pants Plain n
other Shorts Team y
 
can you show us your code which you use to display your recordset on the webpage...

-DNG
 
Here's the code...

<% While ((Repeat1__numRows <> 0) AND (NOT RS_DB.EOF)) %>
<tr>
<td><%=(RS_DB.Fields.Item("AutoNO").Value)%></td>
<td><%=(RS_DB.Fields.Item("VZ_Size").Value)%></td>
<td><%=(RS_DB.Fields.Item("VZ_Desc").Value)%></td>
<td><%=(RS_DB.Fields.Item("VZ_Type").Value)%></td>
<td><%=(RS_DB.Fields.Item("VZ_Ordered").Value)%></td>
</tr>
 
Ok I'm assuming the variable

RS_DB.Fields.Item("VZ_Size").Value

contains the possible values 'tall', 'med', and 'short'.


You can do this (this won't be the most efficient way cause I'm javascript jscript person, not vbscript):
Code:
 <%dim rowColor 
  While ((Repeat1__numRows <> 0) AND (NOT RS_DB.EOF)) 
  if (RS_DB.Fields.Item("VZ_Size").Value == 'tall') then
     rowColor = '#0000ff';
  elseif (RS_DB.Fields.Item("VZ_Size").Value == 'med') then
     rowColor = '#ff0000';
  else
     rowColor = '#ffff00';
  end If    
%>
  <tr style="color:<%=rowColor%>">
    <td><%=(RS_DB.Fields.Item("AutoNO").Value)%></td>
    <td><%=(RS_DB.Fields.Item("VZ_Size").Value)%></td>
    <td><%=(RS_DB.Fields.Item("VZ_Desc").Value)%></td>
    <td><%=(RS_DB.Fields.Item("VZ_Type").Value)%></td>
    <td><%=(RS_DB.Fields.Item("VZ_Ordered").Value)%></td>
  </tr>

<.

 
Didn't work.

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/list/list.asp, line 44, column 47
if (RS_DB.Fields.Item("VZ_Size").Value == 'tall' then
 
Take out the ==
make it =
I don't think I should have to tell you this assuming you wrote that code.

== jscript
= vbScript


<.

 
put this function on the same ASP page

Code:
Function colorRS(val)
Select Case val
 case "tall"
 colorRS = "<font color=""blue"">" & val & "</font>"
 case "short"
 colorRS = "<font color=""yellow"">" & val & "</font>"
 case "med"
 colorRS = "<font color=""red"">" & val & "</font>"
 case else
 colorRS = "<font color=""black"">" & val & "</font>"
End Select
End function

Then do this:

Code:
<% While ((Repeat1__numRows <> 0) AND (NOT RS_DB.EOF)) %>
  <tr>
    <td><%=colorRS(RS_DB.Fields.Item("AutoNO").Value)%></td>
    <td><%=colorRS(RS_DB.Fields.Item("VZ_Size").Value)%></td>
    <td><%=colorRS(RS_DB.Fields.Item("VZ_Desc").Value)%></td>
    <td><%=colorRS(RS_DB.Fields.Item("VZ_Type").Value)%></td>
    <td><%=colorRS(RS_DB.Fields.Item("VZ_Ordered").Value)%></td>
  </tr>


-DNG
 
SWEET!!


It's only adding color to VZ_Size filed and skipping the others, but its ok.


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top