在SSRS2008 R2中隐藏空子报表

时间:2012-02-01 09:51:58

标签: ssrs-2008 reporting-services subreport

我在报告中添加了一个子报告。目标只是在子报表中没有数据时隐藏它。

this thread on Microsoft forums上提到了NoRows属性,但我想这是SSRS 2005作为线程已经很老了。

如果没有数据,是否有隐藏子报告的明显方法?我可以隐藏子报表本身的Tablix,但我还需要隐藏子报表所在的行。为此,我需要指示子报表是否在主报表中包含数据。

你能给出解决这个问题的线索吗?

6 个答案:

答案 0 :(得分:5)

一年前我有类似的问题。我对此的模糊回忆:

我记得的默认行为是,如果子报表中的数据集没有返回任何行,SSRS将不会显示子报表。这可以实现您想要的一半,但不会让父报告知道是否隐藏子报告区域。 IIRC,NoRows属性仅控制在这种情况下显示的内容,但在运行时不容易检查以更改其他属性。

我的最终解决方案是在父报告中创建一个精简查询,指出子报告是否有任何行。我用它来控制行和子报告的可见性。

我怀疑有一个更优雅的答案......

答案 1 :(得分:3)

我将子报表放在自己的行中。然后我在文本编辑器中编辑了rdl文件,并将行高设置为0(设计师不允许你这样做)。

当行高度为0时,该行几乎是隐藏的,直到子报表获取数据,此时子报表确定行高,并且它们再次看起来正常。

编辑rdl的另一种方法可能是在代码中设置行的高度,但我没有考虑过。

答案 2 :(得分:1)

I ran into this issue and none of the answers worked for me. In my case I was converting a Crystal Report to an SSRS report and was using a sub-report that could occur for every group. This was fairly simple in Crystal Reports because you could suppress empty sections with a checkbox.

What worked for me in SSRS and was very clean was to add a subquery/CTE to my main report query that got a count of the number of rows that would be present in the sub-report data. For example:

SELECT CommonCriteria, Count(*) [RowCount]
FROM TableUsedInSubReport
GROUP BY CommonCriteria

Then just join this subquery/CTE to your main query on the common criteria. Once you have this it is very simple as you just right click on the far left of the row in the tablix and select Row Visbility. Then you use an expression such as...

=IIF(Sum(Fields!RowCount.Value) > 0, false, true)

That way if there are any rows to display in the sub report it will display them and if there are no rows in the sub report it will hide it and not leave white space.

答案 3 :(得分:0)

AnarchistGeek

你好,

我自己刚遇到这个问题。 “错误:子报告无法显示”这一丑陋的错误真让我感到烦恼。

解决方案: 为了解决这个问题,我简单地将子报表嵌套在矩形中,并在该矩形的可见性上使用表达式,如此。

离。 = IIF(字段!Field1.Value没有,真,假)
(在我的案例中,Field1是父报告中返回的数据列。)

相应地进行更改:)

答案 4 :(得分:0)

我最终在子报表下面使用了矩形 - 这样如果子报表没有返回任何内容,它下面的矩形将控制单元格的外观 - 在我的情况下,如果子报表没有返回任何内容,我需要将单元格灰化。

这个帖子给了我一个想法How to supress empty subreports in SSRS 2008,但我甚至不必使用表达式,因为默认情况下SSRS如果没有返回任何内容则不会呈现子报告。

答案 5 :(得分:0)

更简单的解决方案是:

  

Sanjay Kumar Rajarao 于2013年10月16日12:15回复访问子报告属性 - 可见性 - 根据表达式显示。输入这个   代码:

     

= IIF(ROWNUMBER(没有)大于0,假,真)

https://community.dynamics.com/gp/f/32/t/114129

相关问题