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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format cell color based on <td> contents

Status
Not open for further replies.

pyroskliq

Technical User
Jan 17, 2001
29
US
Is it possible to format the color of a specific cell based on the contents of the cell?

I have an .asp page that displays the results of a query. My "status" field can return a value of "PROD", "REJECT", or "HOLD".

What I'm attempting to do is to make the cell (or possibly row) a different color depending which of the three values in the "status" field is returned.

I'm not super familiar with .asp (I generally use it to update and retrieve data from a small table). Maybe this isn't an .asp question but javascript?

Thanks.
Brian
 
I'm not the most efficent ASP programmer in the world but his should work

Just test the record set, set the color, then write the output.

Something like this should work

<TABLE>
<TR>
<TD <%if objRS(&quot;FIELDNAME&quot;) = &quot;HOLD&quot; then
Response.write &quot;BGCOLOR=RED&quot;
end if
%>
> 'this line closes the TD tag
<%= objRS(&quot;FIELDNAME&quot;) %> 'this line writes value
</TR>
</TABLE>

Again, probably not the most efficent but it should work.
 
I have an .asp page that displays the results of a query. My &quot;status&quot; field can return a value of &quot;PROD&quot;, &quot;REJECT&quot;, or &quot;HOLD&quot;.

What I'm attempting to do is to make the cell (or possibly row) a different color depending which of the three values in the &quot;status&quot; field is returned.

Dim BGColor
BGColor = &quot;#FFFFFF&quot; ' or whatever your default color is

While looping thru your recordset:

Select Case RecordSet(&quot;Status&quot;)
Case &quot;PROD&quot;
BGColor = &quot;#11FFFF&quot;
Case &quot;REJECT&quot;
BGColor = &quot;#1111FF&quot;
Case &quot;HOLD&quot;
BGColor = &quot;#111111&quot;
Case Else
BGColor = &quot;#FFFFFF
End Select

In your table rows/cells:

<tr bgcolor=&quot;<%=BGColor%>&quot;>

or

<td bgcolor=&quot;<%=BGColor%>&quot;>


does that all make sense?

and I have no idea what colors I selected, I just used different color codes as examples..... s-)
 
Thanks to both of you!

I worked out both methods, and both of them allowed me to do what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top