provides a simple, yet powerful, component called the ReportBook
that allows multiple reports to be combined into one. Doing so makes displaying, printing, and exporting multiple reports a much simpler task for end users. Providing this type of functionality does leave one question though, "How are report parameters handled?" This entry will focus on providing the answers to that simple question. Click here to download the sample code so you can follow along. Creating a ReportBook
ReportBooks are supported in all three environments the ReportViewer supports, WinForms, Silverlight, and ASP.NET. Adding a ReportBook to each of these environments is very similar. This example focuses on using a ReportBook with the WinForms ReportViewer.
- Create a WinForms Application
- Add a reference to the project containing the reports.
- Drag a ReportViewer from the ToolBox into the designer.
- Drag a ReportBook from the ToolBox into the designer.
A dialog will be displayed asking for the reports to be included in the ReportBook.
- Click New
- Select the reports to be included in the report book.
- Click OK
- Click OK
- Set the ReportViewer's Report property to the new ReportBook.
Once all of this has been set up, the ReportViewer will be able to generate and display all of the reports referenced by the ReportBook as a single report. All parameters from all of the included reports will be displayed at the top for users to select. If duplicate parameters exist across the selected reports, they will be merged and displayed as a single parameter. This is explained in more detail below. Note: If the below error message is displayed upon refreshing the ReportViewer, make sure that the connection string for the reports has been added to the App.config for the project containing the ReportViewer.
"Format of the initialization string does not conform to specification starting at index 0." Report Parameters UI
When a ReportBook is bound to a ReportViewer, the ReportViewer is responsible for detecting a displaying the required parameters in its UI. If multiple parameters specify the same name and type, the first discovered parameter is used and the rest are dropped. Displaying parameters in such a way provides a cleaner interface and a more user friendly experience. Report Parameters in Code
In some cases, it may be necessary to specify parameters of reports contained within a ReportBook in code. Since parameter merging really only takes place in the UI, setting the parameter values on the actual ReportBook isn't possible. For these cases, the parameter values will actually need to be set on each individual report before refreshing the ReportViewer.
Parameters can also be set through the ReportBook's Reports collection.
More information about Parameters can be found here.
More information about ReportBooks can be found here.