Subreport Control for a Master-Detail Report
In This Topic
The Subreport control is embedded into the master report which acts as a placeholder for the details report. A parameter passed from the master report to the details report filters the details for each instance of master record and renders the record. Note that there should be a common field in the two reports to establish the master-detail relationship. This field is used to filter data in the details report based on the parameter passed from the master report.
Let us create Master-Detail report using subreport control. The master report will display basic information of employees - Name, Title, City, and Country, along with the list of orders fetched from the details report. Both reports use SQLite Provider, a custom data provider that works if System.Data.SQLite package is added and referenced in the ActiveReports.config file. See setting up the dependencies and configuration file as described in Custom Data Provider topic.
The master report uses the List data region that will contain TextBox controls to display the data. The List data region repeats any report control it contains for every record in the dataset. The master report uses a parameter that is passed from the master report to detail report to filter the details.
The final report will look like as shown.
Create Details Report
In the ActiveReports Designer, create a new RDLX report.
If you are creating a new report in the Visual Studio Integrated Designer, see
Quick Start.
Bind Details Report to Data
As you create a new report, you can configure the report data connection in the Report Wizard. You can also access the Report Data Source dialog by right-clicking the Data Sources node in the Report Explorer and then selecting the Add Data Source option. See SQLite for details.
- On the Choose Data Source Type screen of the wizard, select SQLite and click Next.
- To specify the DataBase Path, click the Browse button and navigate to the desired file on your system. For example, you can connect to the NWind.db sample data source which can be downloaded from GitHub.
- Click Test Connection to test the connection.
- Then click the Next option and configure the dataset by adding a valid query.
- Enter EmployeesDataset into the Name and an SQL query like the following into the text box:
Dataset Query |
Copy Code
|
SELECT * FROM Employees
|
See Query Builder in Microsoft SQL Client and OLEDB Providers for more information on building SQL queries.
- Click Next to proceed to the final screen of the Report Wizard.
- On the final screen of the Report Wizard, review the summary of the report and click Finish to successfully add the report with the SQLite data source.
Design Details Report Layout
(Design view of Details Report)
- Drag and drop the Table control onto the report’s designer.
- From the dataset, drag the following data fields to the Details row of the Table control: [OrderId], [OrderDate], [ShippedDate], [RequiredDate], [ShipVia], and [Freight]. The Header row above the Details row is automatically filled with labels.
- In the Footer row of the table, in the extreme right cell, set the Value property to the following expression =Sum(Fields!Freight.Value).
- Let us add a hidden parameter to the details report. This parameter will be passed form the master report to filter the data in the details report. To add a report parameter that filters the data based on the 'EmployeeID', go to the Report Explorer, right-click Report Parameters, and select Add Parameters.
- In the Report - Parameters dialog that appears, click Add. A parameter, ReportParameter1, is added.
- Select ReportParameter1 to set its properties as follows.
- Set the Data Type property to Integer (since EmployeeID is integer).
- Enable the Hidden property to True.
- Save the report and enter the name of the report as 'subreport-details.rdlx'.
Create a Master Report
In the ActiveReports Designer, create a new RDLX report.
Bind Master Report to Data
As you create a new report, you can configure the report data connection in the Report Wizard. You can also access the Report Data Source dialog by right-clicking the Data Sources node in the Report Explorer and then selecting the Add Data Source option. See SQLite for details.
- On the Choose Data Source Type screen of the wizard, select SQLite and click Next.
- To specify the DataBase Path, click the Browse button and navigate to the desired file on your system. For example, you can connect to the NWind.db sample data source which can be downloaded from GitHub.
- Click Test Connection to test the connection.
- Then click the Next option and configure the dataset by adding a valid query.
- Enter OrdersDataset into the Name and an SQL query like the following into the text box:
Dataset Query |
Copy Code
|
SELECT * FROM Orders
|
- Click Next to proceed to the final screen of the Report Wizard.
- Review the summary of the report and click Finish to successfully add the report with the JSON data source.
Design Master Report Layout
(Design view of Master Report)
- Drag and drop the List data region onto the design area of the report.
- Click Property dialog to open the List dialog.
- In the List dialog, go to Detail Grouping and set the Group on expression to =Fields!EmployeeId.Value.
This ensures the that the data in list is grouped based on [EmployeeId] field.
- Click OK to close the dialog.
- Drag and drop three TextBox controls onto the List and set the Value property of as under:
- For TextBox1, Value ="Name: " & Fields!LastName.Value & ", " & Fields!FirstName.Value
- For TextBox2, Value ="Title: " & Fields!Title.Value
- For TextBox3, Value ="Location: " & Fields!City.Value & ", " & Fields!Country.Value
- Drag and drop the Subreport control onto the List data region as shown.
- In the Properties window, set the ReportName property to the detail report's name (e.g., subreport-details.rdlx).
- To pass the parameter from master report to details report, go to Parameters property and click the ellipses next to '(Collection)'.
- In the Subreport - Parameters dialog, set the Parameter Name to ReportParameter1 (should be same as the report parameter name in details report) and the Parameter Value to =Fields!EmployeeId.Value.
- Click OK to close the dialog.
- To add the report title, drag and drop a TextBox control above the List data region.
- Click inside the text box and enter the text 'Employee Orders Report (Master-Detail Report)'.
- Improve the appearance of the report and preview.
See Also