SSRS组内的交替行颜色

时间:2016-08-19 18:36:38

标签: visual-studio reporting-services ssrs-2008

我在获取备用行颜色方面遇到了一些问题。

我尝试了不同的表达方式,这就像我完成它一样接近:

=IIF(RunningValue(Fields!agent_name.Value,CountDistinct, Nothing) MOD 2 = 1, "Gainsboro", "White")

如果我的所有其他报告都获得了正确的alt行着色,我在使用这个具有Row组和Column组的特定报告时遇到了问题。花了大约2天仍然没有运气:(

当我使用上面的表达式创建行时,它显示如下: result showing using above expression

My Row组显然是名字,

列组是月/年。

非常感谢任何建议/协助

2 个答案:

答案 0 :(得分:2)

问题是数据中有NULL,其中矩阵正在创建没有数据的单元格。由于这些单元格没有关联的Agent_Name,因此它们默认为白色。

我放弃了在SSRS中使用Runnning值和行号,并且通常使用交替行颜色功能。

您在报告中添加了一些 VB代码(报告属性> 代码):

Private bOddRow(10) As Boolean 

Function AlternateColor(ByVal OddColor As String, ByVal EvenColor As String, ByVal Toggle As Boolean, ByVal Type AS INTEGER) As String 

  If Toggle Then bOddRow(Type) = Not bOddRow(Type) 

  If bOddRow(Type) Then 
                Return OddColor 
  Else 
                Return EvenColor 
  End If 

End Function

然后使用表达式填充颜色:

=code.AlternateColor("AliceBlue", "White", 0, 1)

前两个参数是要交替的颜色,第三个参数是指示它切换颜色的控件,第四个参数是用于嵌套分组的组。

该行的第一列包含第一个 1 的控件。

=code.AlternateColor("AliceBlue", "White", 1, 1)

在第一栏中使用 - 您拥有代理商名称。

How to create Alternative Row Background colors in SSRS for values in a group

答案 1 :(得分:1)

Necromancing.
The accepted answer didn't work for me, as the Toggle is very irregular within the column-grouping.

However, the below code worked.

You need to set background-color in the first cell as

=iif(Code.IncrementRunningValue() Mod 2 = 0, "WhiteSmoke", "White")

And in all subsequent cells as

=iif(Code.GetRunningValue() Mod 2 = 0, "WhiteSmoke", "White")

Setting it as group variable will not work, because the sorting is applied after the grouping (which means the rows are re-arranged after the values have been generated).

Private m_s_count As ULong = 0

Public Function IncrementRunningValue() As ULong
    m_s_count = m_s_count + 1UL

    Return m_s_count - 1UL
End Function

Public Function GetRunningValue() As ULong
    Return m_s_count
End Function

Or you can do it even simpler:

Private m_s_AlternatingColor1Count As ULong = 0


Private Function ComputeAlternatingColor1(val As ULong) As String
    If val Mod 2 = 0 Then
        Return "WhiteSmoke"
    End If

    Return "White"
End Function


Public Function IncrementAlternatingColor1() As String
    Dim alternatingColor As String = ComputeAlternatingColor1(m_s_AlternatingColor1Count)
    m_s_AlternatingColor1Count = m_s_AlternatingColor1Count + 1UL

    Return alternatingColor
End Function

Public Function GetAlternatingColor1() As String
    Return ComputeAlternatingColor1(m_s_AlternatingColor1Count)
End Function

and then in the first row's background-color:

=Code.IncrementAlternatingColor1()

and all subsequent rows' background-color:

=Code.GetAlternatingColor1()

That has the advantage that you can switch the colors in ONE place (DRY).