简体   繁体   English

使用Reporting Services将组保留在一个页面上

[英]Keep Group on One Page using Reporting Services

I created a report as part of a C# application using Reporting Services and I cant find some functionality I am used to seeing in other environments. 我使用Reporting Services创建了一个报告作为C#应用程序的一部分,我找不到我以前在其他环境中看到的一些功能。 I believe both MS Access and Crystal reports have an option called "Keep Together" so that you can keep a specific grouping of data on one page instead of the information being split over two pages. 我相信MS Access和Crystal报告都有一个名为“Keep Together”的选项,这样您就可以在一个页面上保留特定的数据分组,而不是将信息分成两页。

How do I do that using 2005 Reporting Services when my report is rendered locally in a C# app and viewed using the .net report viewer. 当我的报表在C#应用程序中本地呈现并使用.net报表查看器查看时,如何使用2005 Reporting Services执行此操作。 Essentially, I want to keep all records for a certain year on one page. 基本上,我想在一个页面上保留特定年份的所有记录。 I am using Visual Studio 2008. 我正在使用Visual Studio 2008。

The year is one of the columns and the number of rows for one year is always smaller than a page. 年份是列之一,一年的行数始终小于页面。 My report uses just one table and has an innermost grouping by year and then another outer grouping by client name. 我的报告只使用一个表,按年度分列最里面的分组,然后按客户名称进行另一个外部分组。

Currently I can fit two years of data on the report, however, if the data starts half way through the first year, then I get the following: 目前我可以在报告中使用两年的数据,但是,如果数据在第一年的中途开始,那么我得到以下内容:

Example: 例:

Page one: 1/2 of 2004 because the data started half way through 04 第一页:2004年的1/2,因为数据在04年中途开始

All of 2005 整个2005年

First half of 2006 2006年上半年

Page2: Second Half of 2006 第2页:2006年下半年

What I would rather do is push all of 2006 to page two. 我宁愿做的是将2006年全部推到第二页。

I am currently using a table for all of the data in the report. 我目前正在使用表格来处理报告中的所有数据。 There is a keep together option at the Table level, but I need one at the Group level. 表级别有一个保持在一起的选项,但我需要一个在组级别。 In this case the Grouping by year. 在这种情况下按年分组。

Any help that can be provided will be much appreciated. 我们非常感谢您提供的任何帮助。

  1. Insert a "List" into the report. 在报告中插入“列表”。
  2. Under its "Tablix Properties" set the "Dataset Name" property to your dataset name. 在其“Tablix属性”下,将“数据集名称”属性设置为数据集名称。
  3. From the design view right-click on the list and then select "Row Group > Group Properties". 在设计视图中右键单击列表,然后选择“行组>组属性”。
  4. On the "Group Properties" window, click "Add" button under "Group Expressions" then choose the field that you want to group within a page. 在“组属性”窗口中,单击“组表达式”下的“添加”按钮,然后选择要在页面中分组的字段。
  5. After that you can insert a "Table" for your detail data inside the row group. 之后,您可以在行组内为您的详细数据插入“表”。
  6. Once you render the report the report will keep data inside the group together between page breaks. 呈现报表后,报表会在分页符之间将数据保留在组内。

Please click on a group which you want to keep together in same page under Row Group section. 请在“行组”部分下的同一页面中单击要保留的组。 After clicking on the desired group make " Keep Together option as True " in properties section. 单击所需的组后,在属性部分中将Keep Together选项设为True ”。 That's it. 而已。 It worked for me. 它对我有用。

Just to add a bit to John's answer. 只是为John的回答添加一点。 For SSRS 2005 the List and Table objects do have a KeepTogether property, which means they will try to keep everything on one page. 对于SSRS 2005,List和Table对象确实具有KeepTogether属性,这意味着它们将尝试将所有内容保留在一个页面上。 I think the best approach is to follow John's advice first though. 我认为最好的方法是首先遵循约翰的建议。

Ok, what you need to do is to first define the reports page size to be large enough to encompass your entire data region. 好的,您需要做的是首先将报告页面大小定义为足以包含整个数据区域。

See: 看到:

http://msdn.microsoft.com/en-us/library/bb677374.aspx http://msdn.microsoft.com/en-us/library/bb677374.aspx

You then need to add Page Break Points to the Group in your Matrix. 然后,您需要在Matrix中向分组添加分页符。 See below: 见下文:

http://msdn.microsoft.com/en-us/library/ms156434.aspx http://msdn.microsoft.com/en-us/library/ms156434.aspx

Use the Rectangle element and copy and paste all the controls into it. 使用Rectangle元素并将所有控件复制并粘贴到其中。 On tke rectangle properties check the box for keeping contents together. 在tke矩形属性上,选中用于将内容保持在一起的框。 Don't include a border if you don't want extra lines. 如果您不想要额外的线条,请不要包含边框。

I had a number of items outside of the matrix element that I need for a footer. 我在页脚元素之外有一些项目,我需要一个页脚。 I only wanted them on the last page, so I couldn't use the standard footer section. 我只想在最后一页上使用它们,所以我无法使用标准页脚部分。 By putting them in rectangle I avoid page breaks in the middle of the group. 通过将它们放在矩形中我避免在组的中间分页。

The problem was that I needed two years on a page and never 1/2 year even if the specific set of records started half way through the year. 问题是我需要在一页上花两年时间,即使特定的记录集开始于一年中的一半,也不需要半年。 It turns out that even though there is a "Keep Together" option at the table level, there is not one at the group level. 事实证明,即使在表级别存在“保持在一起”选项,组级别也没有。 I needed this option at a group level. 我在组级别需要此选项。 Instead of using a format solution I altered the underlying SQL for the report. 我没有使用格式解决方案,而是更改了报表的基础SQL。 In cases where there was only 1/2 year of data I created records for the other part of the year with correct dates, but zeros for all other values. 如果只有1/2年的数据,我为年份的其他部分创建了正确日期的记录,但是所有其他值都为零。 This means that if the page is formatted properly to hold two years then it will always show two complete years and one year will never be broken over two pages. 这意味着如果页面格式正确,可以保存两年,那么它将始终显示两个完整年份,一年将永远不会被打破两页。 I also thought the answers provided by Mozy and John Sansom were good and I voted them both up. 我也认为Mozy和John Sansom提供的答案很好,我把它们都投了出来。

Thanks for the help! 谢谢您的帮助!

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

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