SSRS How to change background color after a field in a tablix

好久不见. 提交于 2020-01-06 22:00:09

问题


I have a tablix table with hundreds of rows of data. I would like to have the background color to be yellow right after a particular condition. How can I do that?

Example - I want all the data to be yellow iif(Fields!pet.Value="cat"), so hamster and on...


回答1:


You need to change the expression for the cell's BackgroundColor and remember what it was. We'll need custom code for this. Go to the Report menu, choose Report Properties... and click on Code and enter the following code:

Dim ThisPetColor As String

Function PetColor(PetType As String) As String
    If ThisPetColor = "" Then
        ThisPetColor = "White"
    End If

    If PetType = "cat" Then
        ThisPetColor = "Yellow"
    Else If PetType = "hamster" Then
        ThisPetColor = "Green"
    Else If PetType = "unicorn" Then
        ThisPetColor = "Purple"
    End If

    Return ThisPetColor 
End Function

Then in your cell make the BackgroundColor expression be:

=Code.PetColor(Fields!pet.Value)

or for even more flexibility in copying the formula, use the built-in Me reference for the textbox:

=Code.PetColor(Me.Value)

So what we are doing is creating a global variable for the pet color ThisPetColor and initialising that to "White". When the type of pet changes, if it is one of the ones where we change color then we change the value of the global variable to be the new pet color and use that thereafter (until the next pet type).



来源:https://stackoverflow.com/questions/33600231/ssrs-how-to-change-background-color-after-a-field-in-a-tablix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!