简体   繁体   English

SSRS在组内交替行颜色

[英]SSRS Alternating Row Colors Within Groups

I have some issues getting alternate row colors. 我在获取备用行颜色时遇到一些问题。

I've tried different expressions and this is as close as I've gotten to getting it done: 我尝试了不同的表达式,而这与完成它的过程差不多:

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

Where all other of my reports are getting correct alt row shading, I'm having trouble with this specific report that has a Row group and a Column group.. Spent about 2 days and still no luck :( 在我所有其他报告都出现正确的alt行阴影的地方,我遇到了这个特定的报告,该报告有一个“行”组和一个“列”组。.花了大约2天,仍然没有运气:(

When I make my rows with the above expression, it is displayed like this: 当我使用上述表达式创建行时,其显示如下: 结果显示使用上面的表达式

My Row group obviously is the name, 我的行组显然是名字,

Column group is the Month/year. 列组是月/年。

Any suggestions / assistance would be greatly appreciated 任何建议/协助将不胜感激

The problem is that there are NULLs in the data where the matrix is creating cells where there is no data. 问题在于,在矩阵创建没有数据的单元格的数据中有NULL。 Since there's no Agent_Name associated for those cells, they default to the white. 由于没有与这些单元格关联的Agent_Name,因此它们默认为白色。

I gave up on using Runnning Values and Row Numbers in SSRS and usually use the Alternating Row Color function. 我放弃了在SSRS中使用“运行值”和“行号”,通常使用“交替行颜色”功能。

You add some VB Code to the report (Report properties > Code): 您将一些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

Then use an expression to populate the colors: 然后使用一个表达式填充颜色:

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

The first two arguments are the colors to alternate between, the third argument is the control that tells it to switch colors, and the fourth argument is for the group to be used for nested grouping. 前两个参数是要在其间切换的颜色,第三个参数是告诉其切换颜色的控件,第四个参数是用于嵌套分组的组。

The first column of the row has the control with the first 1 . 行的第一列具有与第一1中的控制。

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

Use this in your first column - where you have your Agent Name. 在您的第一列中使用此名称-您具有代理商名称。

How to create Alternative Row Background colors in SSRS for values in a group 如何在SSRS中为组中的值创建替代行背景颜色

Necromancing. Necromancing。
The accepted answer didn't work for me, as the Toggle is very irregular within the column-grouping. 接受的答案对我不起作用,因为在列分组中Toggle非常不规则。

However, the below code worked. 但是,以下代码有效。

You need to set background-color in the first cell as 您需要在第一个单元格中将background-color设置为

=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: 然后在第一行的background-color中:

=Code.IncrementAlternatingColor1()

and all subsequent rows' background-color: 以及所有后续行的background-color:

=Code.GetAlternatingColor1()

That has the advantage that you can switch the colors in ONE place (DRY). 这样的好处是您可以将颜色切换到一个位置(干)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM