C# 使用 Reporting Services 将组保持在一页上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/890832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 08:38:18  来源:igfitidea点击:

Keep Group on One Page using Reporting Services

c#.netsql-serverreporting-services

提问by JK.

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. 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.

我使用 Reporting Services 创建了一个报告作为 C# 应用程序的一部分,但我找不到一些我习惯在其他环境中看到的功能。我相信 MS Access 和 Crystal 报告都有一个名为“保持在一起”的选项,这样您就可以将特定的数据分组保留在一页上,而不是将信息分成两页。

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. Essentially, I want to keep all records for a certain year on one page. I am using Visual Studio 2008.

当我的报表在 C# 应用程序中本地呈现并使用 .net 报表查看器查看时,如何使用 2005 Reporting Services 执行此操作。本质上,我想在一页上保留某一年的所有记录。我正在使用 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.

任何可以提供的帮助将不胜感激。

采纳答案by JK.

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. 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. 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.

问题是我在一页上需要两年而不是 1/2 年,即使特定的记录集在一年中开始。事实证明,即使在表级别有一个“保持在一起”选项,但在组级别没有一个选项。我在组级别需要此选项。我没有使用格式解决方案,而是更改了报告的基础 SQL。在只有 1/2 年数据的情况下,我为一年中的其他部分创建了具有正确日期的记录,但所有其他值都为零。这意味着如果页面格式正确以保存两年,那么它将始终显示完整的两年,并且一年永远不会被分成两页。我也认为 Mozy 和 John Sansom 提供的答案很好,我对他们都投了赞成票。

Thanks for the help!

谢谢您的帮助!

回答by John Sansom

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. See below:

然后,您需要将分页点添加到矩阵中的组。见下文:

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

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

回答by Mozy

Just to add a bit to John's answer. For SSRS 2005 the List and Table objects do have a KeepTogether property, which means they will try to keep everything on one page. I think the best approach is to follow John's advice first though.

只是为约翰的答案添加一点。对于 SSRS 2005,List 和 Table 对象确实具有 KeepTogether 属性,这意味着它们将尝试将所有内容保留在一页上。我认为最好的方法是先听从约翰的建议。

回答by coffeehunger

  1. Insert a "List" into the report.
  2. Under its "Tablix Properties" set the "Dataset Name" property to your dataset name.
  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.
  1. 在报告中插入“列表”。
  2. 在其“Tablix 属性”下,将“数据集名称”属性设置为您的数据集名称。
  3. 在设计视图中右键单击列表,然后选择“行组 > 组属性”。
  4. 在“组属性”窗口中,单击“组表达式”下的“添加”按钮,然后选择要在页面内分组的字段。
  5. 之后,您可以在行组中为您的详细数据插入一个“表格”。
  6. 呈现报告后,报告将在分页符之间将组内的数据保存在一起。

回答by Ken Mc

Use the Rectangle element and copy and paste all the controls into it. On tke rectangle properties check the box for keeping contents together. Don't include a border if you don't want extra lines.

使用 Rectangle 元素并将所有控件复制并粘贴到其中。在 tke 矩形属性上,选中用于将内容保持在一起的框。如果您不想要额外的线条,请不要包含边框。

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.

我在矩阵元素之外有许多需要用于页脚的项目。我只希望它们出现在最后一页,所以我不能使用标准的页脚部分。通过将它们放在矩形中,我可以避免在组中间出现分页符。

回答by Mohan Katkam

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. That's it. It worked for me.

请在“行组”部分下单击您要在同一页面中保存在一起的组。单击所需的组后,在属性部分使“保持在一起选项为真”。就是这样。它对我有用。