Table rendering Bug: Setting Background color for SSRS report (RDLC)
Hi, I am facing the issue while trying to create a Report Definition Language Client-side (RDLC) report. I want to set background color to the textbox (used in table) depending on the value. I have used conditional formatting to achieve this. But i am facing issue in setting background color for Some of the fields like EnduranceYoYo Endurance5MinRun The General Format of the Conditional format is =iif(<Varchar Field>.value="NA",Gray.iif(<Integer Field> < 600,"Red",iif(<Integer Field> >=800,"Green","Gold"))) I have used this conditional formatting in Textbox (Properties) --> Background (Expressions) I have tried the following options to rectify the issue Option 1 : This is the format i have used in Conditional formatting in Expression (In Textbox properties -- background -- Expression) for all the columns, to set the background color for the textbox using their individual column names. It is working fine for all the columns except EnduranceYoYo and Endurance5MinRun =Iif(Trim(Fields!RawEnduranceYoYo.Value)=Parameters!NA.Value,Parameters!Gray.Value,iif(Fields!ScoreEnduranceYoYo.Value<600,Parameters!Red.Value,Iif(Fields!ScoreEnduranceYoYo.Value>=800,Parameters!MediumAquamarine.Value,Parameters!Gold.Value))) Option 2 : Checked the null / empty / zero as in the code below to overcome the data issue dr[ "ScoreEnduranceYoYo" ] = dr[ "ScoreEnduranceYoYo" ] == System. DBNull .Value == true || dr[ "ScoreEnduranceYoYo" ].ToString() == string .Empty || dr[ "ScoreEnduranceYoYo" ].ToString() == "0" ? "0" : dr[ "ScoreEnduranceYoYo" ].ToString(); Option 3 : Added as a parameter and assigned the parameter to that text box. parameters.Add( new ReportParameter ( "EnduranceYoYo" , "Iif(Trim(Fields!RawEnduranceYoYo.Value)=Parameters!NA.Value,Parameters!Gray.Value,iif(Fields!ScoreEnduranceYoYo.Value<600,Parameters!Red.Value,Iif(Fields!ScoreEnduranceYoYo.Value>=800,Parameters!MediumAquamarine.Value,Parameters!Gold.Value)))" )); Option 4 : Step 1: Created a function as shown below in the Report --> Report Properties --> Code Tab (refer the image below for your reference) public Function GetSelectedColor(Raw as string,Fast as integer) as string if Raw.Trim() = "NA" Then return "Gray" else if Fast < 600 Then return "Red" else if Fast >= 800 Then return "MediumAquamarine" else return "Gold" end if end if end function Step 2: I have called that function in the textbox background Expression to display the background color. Refer the image below for your reference. Note: Before compiling we are getting an error “unidentifier expected”. While we compile that file: The BackgroundColor expression for the textbox ‘textbox58’ contains an error: [BC30456] 'GetSelectedColor' is not a member of 'ReportExprHostImpl.CustomCodeProxy'. C:\FSI\Products\Portals\EpasDeconstruction\Reports\TrafficLightReport.rdlc Option 5 : We also tried to create an assembly in the project in which we get an error saying duplicate. We have added the class in the AssemblyInfo.cs as below (Refer the image below for your reference] public class TestReport { public static string GetSelectedColor(string Raw, int Fast) { string selectedColor; if (Raw.Trim() == "NA") selectedColor = Literals.TLRGray; else { if (Fast < 600) selectedColor = Literals.TLRRed; else if (Fast >= 800) selectedColor = Literals.TLRMediumAquamarine; else selectedColor = Literals.TLRGold; } return selectedColor; } } Step 2: In the report properties --> reference Tab, We have added the project dll as reference as shown in the image below. Here too we are unable to call the function in the textbox properties à background (Expression).Refer the image below for your reference .I have faced the same error “unidentifier expected” Kindly guide me to overcome this issue. Thanks in Advance Ganga
October 28th, 2010 6:09am

Hi Ganga, For option1, please try the following expression: =Iif(Trim(Fields!RawEnduranceYoYo.Value)=Parameters!NA.Value,Parameters!Gray.Value, IIF(Trim(Fields!RawEnduranceYoYo.Value)=Parameters!NA.Value, nothing, iif(Fields!ScoreEnduranceYoYo.Value<600,Parameters!Red.Value,Iif(Fields!ScoreEnduranceYoYo.Value>=800,Parameters!MediumAquamarine.Value,Parameters!Gold.Value)))) Just a confirmation, I don't find EnduranceYoYo and Endurance5MinRun in the expression, it is expected? For option2, please try the following expression: =Iif(Trim(Fields!RawEnduranceYoYo.Value)="0",Parameters!Gray.Value, IIF(Trim(Fields!RawEnduranceYoYo.Value)="0", nothing, iif(Fields!ScoreEnduranceYoYo.Value<600,Parameters!Red.Value,Iif(Fields!ScoreEnduranceYoYo.Value>=800,Parameters!MediumAquamarine.Value,Parameters!Gold.Value)))) For option3, please try the following code: parameters.Add( new ReportParameter ( "EnduranceYoYo" , "=Iif(Trim(Fields!RawEnduranceYoYo.Value)=Parameters!NA.Value,Parameters!Gray.Value, IIF(Trim(Fields!RawEnduranceYoYo.Value)=Parameters!NA.Value, nothing, iif(Fields!ScoreEnduranceYoYo.Value<600,Parameters!Red.Value,Iif(Fields!ScoreEnduranceYoYo.Value>=800,Parameters!MediumAquamarine.Value,Parameters!Gold.Value))))" )); For option4, please use the following expression: =Code.GetSelectedColor(raw, fast) Note, please replace raw and fast with actual value. For option5, please use the following expression: =namespace.TestReport.GetSelectedColor(raw, fast) Note, please replace raw and fast with actual value. Please replace namespace with the actual namespace that is defined in the assembly. If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
November 3rd, 2010 4:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics