Working with Subreports

Within Crystal Reports .NET, multiple subreports can be combined into one main report, which allows you to create information-rich reports from multiple sources and display this information side by side.

Both linked and unlinked subreports are available in the code download, found in the solution: C:\CrystalReports\Chapter02\Demo\Chapter2.sln. Open and run this solution from Visual Studio .NET and choose the report from the drop-down box at the top right of the window.

To run the unlinked report, you will need access to the Northwind sample database.

Subreports come in two varieties—unlinked and linked. Unlinked subreports allow you to insert subreports that are totally unrelated to the main report content. In Figure 3-35, a sales graph has been inserted into an employee listing report (included in the sample files as employee_listing_unlinked.rpt). Both of these reports were developed independently and are from different tables and a different data source.

The second type of report is the linked subreport. Linked subreports allow the passing of parameters and variables between the main report and the subreport, which can be used to filter the subreport content. The report shown in Figure 3-36 has a main report that is the same employee listing report, only this time a linked subreport has been inserted showing a commission amount for each employee (included in the sample files as employee_listing_linked.rpt). The commission report is a separate report, but it is inserted into the details section and linked on the employee ID field.

Figure 3-36

For each employee, the subreport is run again, and the employee ID is used in record selection on the subreport. When the page is printed, each instance of the subreport is printed next to the corresponding employee, with only their details shown.

Was this article helpful?

0 0

Post a comment