0
votes

We use a ReportViewer control for report hosting and generation in a Windows Application.

The report is a .rdlc (several in fact with sub reports), and runs local.

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

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

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. But of course the global PageNumber is not available in the report body.

I would love to hear any ideas, as to how it might be possible to control footer contents dynamically based on report data.

1

1 Answers

0
votes

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

This value can then be referenced in the footer via 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.

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)