Quizzes & Puzzles3 mins ago
Dreamweaver
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?
Answers
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?
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?
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.
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>
(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>