Click to See Complete Forum and Search --> : change cell color - via asp/sql variable


chaundy
02-12-2007, 07:35 AM
hello,

I have a table in ASP that take some info from an access database. it lists it in a table. i want to set one cell or row depending on its value. value is always going to be 2 or 3 or 4. i am out putting the value like this;

rstSearch.Fields("Field2").Value

want 2=red 3=blue etc

hope someone can help. not sure if i should do it in the <td bgcolor=> tag or use a variable. hope someone can help me. below is my code for the whole table:


%>

<tr>
<td bgcolor="#D4E5F5"><FONT SIZE="-1"><%= rstSearch.Fields("Field1").Value %></td>
<td bgcolor="#D4E5F5"><FONT SIZE="-1"><%= rstSearch.Fields("Field2").Value %></td>
<td width=120 bgcolor="#D4E5F5"><FONT SIZE="-1"><%= rstSearch.Fields("Field3").Value %></td>
<td width=120 bgcolor="#D4E5F5"><FONT SIZE="-1"><%= rstSearch.Fields("Field4").Value %></td>
<td width=120 bgcolor="#D4E5F5"><FONT SIZE="-1"><%= rstSearch.Fields("Field5").Value %></td>
<td bgcolor="#D4E5F5"><FONT SIZE="-1"><%= rstSearch.Fields("Field10").Value %></td>
<td bgcolor="#D4E5F5"><FONT SIZE="-3"><%= rstSearch.Fields("Field11").Value %></FONT></td>
</tr>

<%


cheers


PAUL

mtm81
02-12-2007, 07:41 AM
ok have it like this:

Dim CellColour

While not rstSearch.EOF
'first clear off the previous loop colour just to be safe
CellColour = ""
If rstSearch.Fields("Field2").Value = "2" then
CellColour = 'put your # colour ref here
elseif rstSearch.Fields("Field2").Value = "3" then
CellColour = 'put your # colour ref here
else
'the final option sets it to be a certain colour if any of the above else's are not found (i.e if it's not a value of 2 or 3 then it can only be 4 so we just use an else instead of an elseif
CellColour = ""

end if

%>

<!--Then your table code below -->
<tr>
<td bgcolor="<%=CellColour%>"><FONT SIZE="-1"><%= rstSearch.Fields("Field1").Value %></td>
<td bgcolor="<%=CellColour%>"><FONT SIZE="-1"><%= rstSearch.Fields("Field2").Value %></td>
<td width=120 bgcolor="<%=CellColour%>"><FONT SIZE="-1"><%= rstSearch.Fields("Field3").Value %></td>
<td width=120 bgcolor="<%=CellColour%>"><FONT SIZE="-1"><%= rstSearch.Fields("Field4").Value %></td>
<td width=120 bgcolor="<%=CellColour%>"><FONT SIZE="-1"><%= rstSearch.Fields("Field5").Value %></td>
<td bgcolor="<%=CellColour%>"><FONT SIZE="-1"><%= rstSearch.Fields("Field10").Value %></td>
<td bgcolor="<%=CellColour%>"><FONT SIZE="-3"><%= rstSearch.Fields("Field11").Value %></FONT></td>
</tr>