Text Color Based on DB Value

C

Chris Stanley

I am using dreamweaver to make an ASP page. I have a table of data
from a MSSQL database that is currently showing on the ASP page. I
want the ability to change the color based on a priority number that's
in the MSSQL database (same recordset that the data comes from). I
don't have the priority field out on the page but can put it out if
need be. I have 3 different priority numbers and if the first row is
priority 1 I want the font to be red and if the second row is priority
2 I want the color to be yellow and so on.

Thanks

Chris
 
A

Aaron Bertrand [SQL Server MVP]

col = rs("priority")
if col = 1 then
fontcolor = "#FF0000"
elseif col = 2 then
fontcolor = "#FFFF00"
end if
response.write "<span style='color:" & fontcolor & "'>" & stuff & "</span>"
 
C

Chris Stanley

Thanks for the quick response. Is there a certain place I need to put
this code???

Chris
 
R

Ray Costanzo [MVP]

Chris Stanley said:
I am using dreamweaver to make an ASP page.
8|

I have a table of data
from a MSSQL database that is currently showing on the ASP page. I
want the ability to change the color based on a priority number that's
in the MSSQL database (same recordset that the data comes from). I
don't have the priority field out on the page but can put it out if
need be. I have 3 different priority numbers and if the first row is
priority 1 I want the font to be red and if the second row is priority
2 I want the color to be yellow and so on.


You could use the priority number in your CSS class name like so:


<style type="text/css">
tr.priority1 { background-color: #ff0000; }
tr.priority2 { background-color: #ffff00; }
tr.priorityAndSoOn { background-color: #AndSoOn; }
</style>


<%
Do While Not yourRS.EOF
sPriority = yourRS.Fields.Item("Priority").Value & "")
%>
<tr class="priority<%=sPriority%>">
<td><%=yourRS.Fields.Item("something").Value%></td>
...
</tr>
<%
yourRS.MoveNext
Loop
%>

Ray at work
 
A

Aaron Bertrand [SQL Server MVP]

tr.priority1 { background-color: #ff0000; }
tr.priority2 { background-color: #ffff00; }

Ooh, I like that approach even better than my suggestion.

I get light-headed when I see HTML code that is half <font color=#blah>
tags... especially when they're all the same. I always find myself pounding
my head against the wall, dying to ask when they're going to look up this
"CSS" concept they may have heard about.
 
C

Chris Stanley

I'm very new to CSS, is this something DWeaver can do in the CSS
Styles??? or do I need to just use the code above??

Chris
 
R

Ray Costanzo [MVP]

I'm trying my best always to use CSS, but it gets my goat. Unless I'm
missing something, not ~every~ inline attribute has a CSS equivalent, and
that's frustrating!

Ray at work
 
C

Chris Stanley

I haven't gotten anything to work so far. I'm probably doing something
wrong. I tried the first code but no color changes. I didn't try the
CSS b/c I don't really know what to do with it. I am very new to this.

Chris
 
C

Chris Hohmann

Ray Costanzo said:
I'm trying my best always to use CSS, but it gets my goat. Unless I'm
missing something, not ~every~ inline attribute has a CSS equivalent, and
that's frustrating!

Are you just going to leave us hanging like that!? :) What inline display
attribute is not represented in CSS? Also, which version of CSS are we
talking about 1, 2, 2.1, 3? Inquiring minds want to know.
 
C

Chris Hohmann

Chris Stanley said:
I haven't gotten anything to work so far. I'm probably doing something
wrong. I tried the first code but no color changes. I didn't try the
CSS b/c I don't really know what to do with it. I am very new to this.

Can you show us the code you have thus far?
 
C

Chris Stanley

OK, here's my code:

<html>
<head>
<title>Surry County E-911 Active Calls</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">
<!--
-->
</style>
<style type="text/css">
<!--
-->
</style>
<meta http-equiv="Refresh" content="30">
</head>

<body bgcolor="#000000">
<div align="center">
<p><font color="#FFFFFF" size="7" face="Tahoma">Surry County E-911
Active Calls</font></p>
<p>&nbsp;</p>

<p><font color="#FF0000"> </MM:DECORATION></font></p>
<table width="97%" border="0" align="center">
<tr>
<td width="14%"><div align="left"><font color="#FF0000" size="5"
face="Tahoma">Call
Number</font></div></td>
<td width="16%"><div align="left"><font color="#FF0000" size="5"
face="Tahoma">Complaint</font></div></td>
<td width="38%"><div align="left"><font color="#FF0000" size="5"
face="Tahoma">Incident
Location</font></div></td>
<td width="18%"><div align="left"><font color="#FF0000" size="5"
face="Tahoma">City</font></div></td>
<td width="14%"><div align="left"><font color="#FF0000" size="5"
face="Tahoma">
Unit</font></div></td>
</tr>
</table>
<hr>
<p>&nbsp;</p>
<MM_REPEATEDREGION NAME="Repeat1" SOURCE="Recordset1"><MM:DECORATION
OUTLINE="Repeat" OUTLINEID=1>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<table width="97%" border="0" align="center">
<tr>
<td width="15%"><font color="#00FFFF"><strong><font size="3"
face="Tahoma"><%=(Recordset1.Fields.Item("Call_Number").Value)%></font></strong></font></td>
<td width="16%"><font color="#00FFFF"><strong><font size="3"
face="Tahoma"><%=(Recordset1.Fields.Item("Complaint").Value)%></font></strong></font></td>
<td width="38%"><div align="left"><font color="#00FFFF"
size="3"><strong><font
face="Tahoma"><%=(Recordset1.Fields.Item("Actual_Incid_Location").Value)%></font></strong></font></div></td>
<td width="18%"><font color="#00FFFF"><strong><font size="3"
face="Tahoma"><%=(Recordset1.Fields.Item("Actual_Incid_City").Value)%></font></strong></font></td>
<td width="13%"><font color="#00FFFF"><strong><font size="3"
face="Tahoma"><%=(Recordset1.Fields.Item("First_Unit").Value)%></font></strong></font></td>
</tr>
</table>
<%

Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
<font color="#FF0000"> </font>
<p>&nbsp;</p>
<p align="left"><font color="#FFFFFF" size="5" face="Tahoma">Total
Active Calls:
<%=(Recordset1_total)%></font></p>
<p align="left">&nbsp;</p>

</div>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>


Thanks

Chris
 
R

Ray Costanzo [MVP]

Well, in a way I spoke too soon. I guess I was thinking of cellpadding and
cellspacing, but I do understand that the padding and margin of the ~cells~
replace those! But what about something as basic AND COMMON as <table
align="center">?

I think what I'm most upset about is the fact that a span can't have a width
(strictly speaking). I hate that.

Ray at home
 
R

Ray Costanzo [MVP]

I don't see anything that's an attempt to change colors. ?? I think your
first step would be to get rid of those <font> tags you have. How about:

<style type="text/css">
tr.priority1 { background-color: #ff0000; }
tr.priority2 { background-color: #ffff00; }
</style>

<table width="97%" border="0" align="center">
<tr class="priority<%=Recordset1.Fields.Item("Priority").Value%>">
<td
width="15%"><%=(Recordset1.Fields.Item("Call_Number").Value)%></td>
<td width="16%"><%=(Recordset1.Fields.Item("Complaint").Value)%></td>
<td
width="38%"><%=(Recordset1.Fields.Item("Actual_Incid_Location").Value)%></td>
<td
width="18%"><%=(Recordset1.Fields.Item("Actual_Incid_City").Value)%></td>
<td width="13%"><%=(Recordset1.Fields.Item("First_Unit").Value)%></td>
</tr>
</table>


I know this is easier said than done, but your first step actually ought to
be to stop using Dreamweaver for code writing. If you want to use it for
design, that's one thing, but it shouldn't be used for ASP code, imo.

Ray at home
 
A

Adrienne

Gazing into my crystal ball I observed "Ray Costanzo [MVP]" <my first
name at lane 34 dot commercial> writing in
Well, in a way I spoke too soon. I guess I was thinking of cellpadding
and cellspacing, but I do understand that the padding and margin of the
~cells~ replace those! But what about something as basic AND COMMON as
<table align="center">?

table {text-align:center} /*centers the table content */
table {margin-left:auto; margin-right:auto; width:whatever} /* centers the
~table~ in the viewport*/
I think what I'm most upset about is the fact that a span can't have a
width (strictly speaking).

Span is an inline element, you really wouldn't want it to have width. But,
you can always use display:block and then set a width. There is also
display:table-inline, etc., but these some of these are not supported by
our favorite browser. I very rarely use span, I usually style the element.
I hate that.

What I really hate is max and min width not supported by IE, position:fixed
not supported by IE, hover pseudo class only working for the A element in
IE, alpha transparency in PNGs not supported by IE. If I could, I would go
to everyone's Windows computer, remove IE, and replace it with Opera or
Firefox.
 
R

Ray Costanzo [MVP]

table {text-align:center} /*centers the table content */
table {margin-left:auto; margin-right:auto; width:whatever} /* centers the
~table~ in the viewport*/

The margin one is the work-around that I would typically use, but then I
decide that it just makes 100 times more sense to stop being so absolute and
just use the inline align="center" attribute, as much as I hate to do it.

Span is an inline element, you really wouldn't want it to have width. But,
you can always use display:block and then set a width. There is also
display:table-inline, etc., but these some of these are not supported by
our favorite browser. I very rarely use span, I usually style the
element.

I understand why the span doesn't have a width, but I disagree with it. And
as far as the display:block, that kinda defeats the purpose of the span.
Also, if you want to get technical, I want to say that as soon as you do a
display:inline to a block element like a table, that will void any width
styles in strict browsers. 8[


What I really hate is max and min width not supported by IE, position:fixed
not supported by IE, hover pseudo class only working for the A element in
IE, alpha transparency in PNGs not supported by IE. If I could, I would go
to everyone's Windows computer, remove IE, and replace it with Opera or
Firefox.

I'm just going to start writing console applications. :]

Rya at work
 
C

Chris Hohmann

Adrienne said:
What I really hate is max and min width not supported by IE,
position:fixed
not supported by IE, hover pseudo class only working for the A element in
IE, alpha transparency in PNGs not supported by IE. If I could, I would
go
to everyone's Windows computer, remove IE, and replace it with Opera or
Firefox.

Amen to that! Just give us hover pseudo class support for lists and I'd be
satisfied. We could then do away with JavaScript menus altogether. Hopefully
the powers that be are listening. :) Here's a CSS/DHTML hybrid that uses
behaviors to add support for Internet Explorer, if anyone is interested.

http://www.brothercake.com/scripts/navmeister/page.php
 
A

Aaron Bertrand [SQL Server MVP]

I understand why the span doesn't have a width, but I disagree with it.

If it's a <div> then use a <div>. A span is contained within another
element that has some kind of defined width. If you need to define widths
inside that way, then as much as I hate to suggest it, I would say use a
table instead (or the very complex kind of CSS that properly replicates a
table, but in a much more cumbersome fashion).
 
R

Ray Costanzo [MVP]

I usually do wind up using tables when I'm trying to avoid doing so. I
can't use a DIV in place of where I want a span with a width, because I'm
wanting an inline element with a width specified. Like:

<style type="text/css">
div.tabs span { width: 200px; border: 1px solid #000000; }
</style>

<div class="tabs">
<span>Tab 1</span>
<span>Tab 2</span>
<span>This is Tab #3</span>
</div>

Since the width won't be honored in strict browsers, I do wind up throwing
it in a table. (Perhaps this isn't the best example.) Again, though,
there's nothing wrong with tables. It's just kinda, uh, fun to try to not
use them.

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top