This topic is locked

Cell Formatting

11/5/2006 6:29:58 PM
ASPRunnerPro General questions
C
Codea author

Hi,

I have created several reports using AspRunner Pro 4.1 and would like to know how I can set the Cell backround colour by a value i.e. if the cell (Field) contains a date (or not null) it is grey or if the field is a yes/no field, green for yes and no is no colour. I looked at Orit's Topic and saw Sergey's response but I could not find where to add the code in my .._list.asp. Any suggestions? Please bare in mind I'm a novice in building asp pages and any help would be greatly appreciated.
Many Thanks

Tony (Australia)

Sergey Kornilov admin 11/6/2006

Tony,
you can set View as type of this field to Custom and try the following code:

str = "<table width=100% bgcolor="

if clng(strValue)>2000 then

str = str & "red"

else

str = str & "blue"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str


In this example I set background color to red if field value is greater than 2000 and to blue in other case.

C
Codea author 11/8/2006

Hi Sergey,

Thanks for the response. I got it to half work. I modified the code as follows:-
str = "<table width=100% bgcolor="

if (strValue)=Yes then

str = str & "grey"

else

str = str & "white"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"
What this actually did was any any cell with a value (i.e. Yes, No and NA) in the column, was given a backround of white. Any Idea what I have done wrong?
Am I restricted to what I colours I can use for cell backround?
Cheers

Tony

Tony,

you can set View as type of this field to Custom and try the following code:

str = "<table width=100% bgcolor="

if clng(strValue)>2000 then

str = str & "red"

else

str = str & "blue"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str


In this example I set background color to red if field value is greater than 2000 and to blue in other case.

J
Jane 11/8/2006

Tony,
if your field type is text you need to use double quotes:

str = "<table width=100% bgcolor="

if strValue="Yes" then

str = str & "grey"

else

str = str & "white"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

C
Codea author 11/13/2006

Tony,

if your field type is text you need to use double quotes:


Hi Jane,

Your suggestion put me in the right direction it just needed an extra line. Thank you very much for help.
str = "<table width=100% bgcolor="

strValue=Left(strValue,3)

if (strValue)="Yes" then

str = str & "#999999"

else

str = str & ""

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str
Now, by adding this in custom code in the "View As" screen, when I export the data in the report into Excel, all the code in the customised cell (see above) is exported instead of the value in the cell. Any Ideas? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=12807&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

Cheers

Tony

Sergey Kornilov admin 11/14/2006

Tony,
nothing is wrong here. This code produces some HTML which looks nice on the list page however is not necessary on the Export page. You can use the following workaround. See my changes in bold:

if InStr(Request.ServerVariables("SCRIPT_NAME"), "_export")<1 then

str = "<table width=100% bgcolor="

strValue=Left(strValue,3)

if (strValue)="Yes" then

str = str & "#999999"

else

str = str & ""

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str

end if

C
Codea author 11/14/2006

Tony,

nothing is wrong here. This code produces some HTML which looks nice on the list page however is not necessary on the Export page. You can use the following workaround. See my changes in bold:


Sensational Sergey!! Worked a treat! U da man!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=12849&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

Cheers

Tony