Conditional cell shading of table in classic asp page

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.
jlcannonAsked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org 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

0
 
jlcannonAuthor Commented:
excellent, thank you this worked perfectly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.