Donate SIGN UP

Dreamweaver

Avatar Image
Kerplunk | 09:37 Thu 01st Dec 2005 | Technology
6 Answers
I have an active server page with a table using dynamic data. I want to put a condition on one of the cells so that if it is empty it will have a red background. Anyone any tips on how I can achieve this?
Gravatar

Answers

1 to 6 of 6rss feed

Best Answer

No best answer has yet been selected by Kerplunk. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
In the "td" tag put an if statement.
If your dynamic data = null (or even if length of your variable name = 0) then
response.write "style='background-color:red' "
end if (close td tag and write the table contents, possibly as a non-breaking space)

It'd be tidier to use a css class instead of this "style="


Does this make sense?
Question Author

stevie21 thanks for your answer,


Is it possible you could post the correct coding eg.


<td><if Recordset1.field1 = null then response.write "style='background-color:red'" endif>


<%=(Recordset1.Fields.Item("field1").Value)%></td>


This code is not working for me. What have I done wrong?


Firstly, you've instantly closed the "td" tag : the if statement needs to be inside it.
Just for simplicity, if we can call your recordset field value "Kerplunker", then the code would be either

<td <% if isNull(Kerplunker) then
Response.Write "style='background-color:red' "
end if %>
>
One line up from here, OUTSIDE the if statement, the 1st td tag is ended. Otherwise you'd have
<td style='blah'
rather than
<td style='blah' >

Or you could start the asp with
<% if len(Kerplunker)=0 then ...

Finally, you could also
Response.Write "class='someClassThatHasRedBackground' "
if you're using stylesheets.


FINALLY - if Kerplunker is null then in the table cell contents you may also want to have
if isNull(Kerplunker) then
Response.Write " "
else
Response.Write Kerplunker
end if

I think empty table cells look odd if they don't have this nbsp code.
In my FINALLY bit there, the first Response.Write should have the
(ampersand symbol) nbsp (semicolon)

This would all come after the first "td" tag is opened and before the other "/td" is closed. You could append </td> the end of each Response.Write here, or just have one </td> after the "end if " :

end if%> </td>
Question Author

Excellent, thankyou very much for the help. I am pretty new to this but am picking it up slowly.


Thanks again.


I'm still picking it up slowly ;-)

1 to 6 of 6rss feed

Do you know the answer?

Dreamweaver

Answer Question >>