Conditional cell shading of table in classic asp page

jlcannon
jlcannon used Ask the Experts™
on
I have an ASP page that displays data pulled from an excel sheet with a named range called "tblData" in the cell of the table where I have a percentage number I want to make it to where if the number is between 1 and 5 then the cell is green. if the umber is between 6 and 8 its yellow, then if its over 8 its red. this is what I have now:

<%
If rs.Fields("2017 Rate") >= 1 OR rs.Fields("2017 Rate") <= 5 then
	Response.Write "<td bgcolor='green' style='width: 301px; height: 21px;' class='auto-style3'>"
Elseif rs.Fields("2017 Rate") >= 6 OR rs.Fields("2017 Rate") <= 8 then
	Response.Write "<td bgcolor='yellow' style'width: 301px; height: 21px;' class='auto-style3'>"
Elseif rs.Fields("2017 Rate") >= 8 then
    Response.Write "<td bgcolor='red' style'width: 301px; height: 21px;' class='auto-style3'>"
End If
%>
<strong>
<%=rs.fields("2017 Rate")%>
</strong></td>

Open in new window


and it just colors all the cells in that column green regardless of the number.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Web Ninja at large
Commented:
You'll need to convert the database to a numeric value, then do your check. You also need to use the AND clause in your IF statementsI've rewritten your code to be a bit more simple:

<%
dim rate : rate = CInt( rs.Fields("2017 Rate") )
color = "red"    '-- color for when rate > 8

If rate >= 1 AND rate <= 5 then
	color = "green"
Elseif rate >= 6 AND rate <= 8 then
	color = "yellow"
end if
Response.Write "<td bgcolor='" & color & "' style'width: 301px; height: 21px;' class='auto-style3'>"
%>
<strong>
<%=rate%>
</strong></td>

Open in new window

Author

Commented:
excellent, thank you this worked perfectly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial