简体   繁体   English

SSRS(Winforms-RDLC)2016。基于行数据控制页脚内容

[英]SSRS (Winforms - RDLC) 2016. Control footer contents based on Row data

We use a ReportViewer control for report hosting and generation in a Windows Application. 我们使用ReportViewer控件在Windows应用程序中托管和生成报告。

The report is a .rdlc (several in fact with sub reports), and runs local. 该报告是.rdlc(实际上有几个带有子报告),并且在本地运行。

I need to gain additional control over the contents in the footer which is now required to show minimal chart data, which is sensitive to the section of the report. 我需要对页脚中的内容进行更多控制,现在该页脚需要显示最少的图表数据,该数据对报告的部分敏感。

I understand that I cannot put a chart in the footer, that is no issue though, as I can generate the images needed for the footer up front, however I still need a way of linking the correct images into the footer. 我知道我无法在页脚中放置图表,但这没问题,因为我可以预先生成页脚所需的图像,但是我仍然需要一种将正确的图像链接到页脚中的方法。

There are some global pages, which all would contain the same footer image along with the global PageNumber. 有一些全局页面,它们都将包含相同的页脚图像以及全局PageNumber。 These compose the first few pages and the last couple of pages. 这些组成前几页和后几页。 So basically these are fine. 所以基本上这些都很好。

There are also some dynamic report sections in the middle of the report, these are a series of sub reports in a Tablix, and each of these sections, which could span multiple pages, would have a specific report footer set by the datasets row key for the current section. 报告的中间还有一些动态报告部分,它们是Tablix中的一系列子报告,并且这些部分中的每一个都可以跨越多个页面,并通过数据集的行键设置了特定的报告页脚当前部分。 The Tablix passes this id Through to the SubReports as a parameter, so I had an idea that I could use a function instead of setting the parameter directly. Tablix将此id作为参数传递给SubReports,因此我有一个想法,我可以使用函数而不是直接设置参数。

The idea here was to update a global variable in code which could be accessed within the footer to provide a dynamic element to any image path. 这里的想法是更新代码中的全局变量,该变量可以在页脚中访问以为任何图像路径提供动态元素。

public shared dim HeaderIndex as Int32 = 0

Public Function HeaderPassThrough(ByVal index As Int32) As Int32 
  HeaderIndex = index
  Return index
End Function

As you may already know it does not work, whenever the footer queries the value of Code.HeaderIndex it is the value of the very last section to process. 您可能已经知道它不起作用,每当页脚查询Code.HeaderIndex的值时,它就是要处理的最后一部分的值。 So, the footer generates after the body of the report it would seem. 因此,页脚将在报表正文之后生成它。

There is no way I can reasonably know the page numbers in advance, 1 section might flow to a single page, another 20, so any custom content I generate to go in the footer, will be generated based on that HeaderIndex, not a page number. 我无法事先合理地知道页码,一个部分可能会流到单个页面,另外20个部分会流到页脚,因此我生成的要放在页脚中的任何自定义内容都将基于HeaderIndex而不是页码来生成。

I then thought is there a way to get the page number into the page, as in this case an array of page number / HeaderIndex could be stored, and then referenced by the footer. 然后,我想到了一种将页码放入页面的方法,因为在这种情况下,可以存储页码/ HeaderIndex的数组,然后由页脚引用。 But of course the global PageNumber is not available in the report body. 但是,当然,全局PageNumber在报表正文中不可用。

I would love to hear any ideas, as to how it might be possible to control footer contents dynamically based on report data. 我很乐意听到任何关于如何根据报表数据动态控制页脚内容的想法。

The solution turned out to be less than obvious. 事实证明,解决方案并不明显。

I added a TextBox to the Tablix containing the sub reports, and set the value of that TextBox to the Data key that I needed, I named it HeaderIndex 我在包含子报表的Tablix中添加了一个TextBox,并将该TextBox的值设置为所需的Data键,将其命名为HeaderIndex

This value can then be referenced in the footer via ReportItems!HeaderIndex.Value 然后可以通过ReportItems!HeaderIndex.Value在页脚中引用此值ReportItems!HeaderIndex.Value

This was however only part of the solution as the value would only be populated on the first page of the subreport. 但是,这只是解决方案的一部分,因为该值只会填充在子报表的第一页上。

So I added the following function to the Report code section : 因此,我在“报告代码”部分添加了以下功能:

public shared dim LastHeaderIndex as Int32 = 0

Public Function HeaderPassThrough(ByVal index As String) As String
  If Index = "" Then
      Return LastHeaderIndex.ToString()
  Else
      LastHeaderIndex = Integer.Parse(index)
  End IF  
  Return index
End Function

So now I can generate footer images in advance of rendering the report and save them on the filesystem keyed via the HeaderIndex. 因此,现在我可以在呈现报告之前生成页脚图像,并将它们保存在通过HeaderIndex键控的文件系统中。

The path for each image in the footer can then be an expression that includes the following (which provides the section identifier that the footer is under): 然后,页脚中每个图像的路径可以是一个包含以下内容的表达式(提供了页脚所在的节标识符):

=Code.HeaderPassThrough(ReportItems!HeaderIndex.Value)

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

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