ActiveReports 18 .NET Edition
Report Authors: Designer Components / Design Reports / Design Page/RDLX Reports / Tutorials: Report Controls in Page/RDLX Reports / Master-Detail Report with Subreport Control
In This Topic
    Master-Detail Report with Subreport Control
    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.

    Master-Detail Report at Preview

    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.   

    1. On the Choose Data Source Type screen of the wizard, select SQLite and click Next.
    2. 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.
    3. Click Test Connection to test the connection.
    4. Then click the Next option and configure the dataset by adding a valid query.
    5. 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.
    6. Click Next to proceed to the final screen of the Report Wizard.
    7. 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


    Details Report Layout at Design
    (Design view of Details Report)

    1. Drag and drop the Table control onto the report’s designer.
    2. 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.
    3. In the Footer row of the table, in the extreme right cell, set the Value property to the following expression =Sum(Fields!Freight.Value).   
    4. 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.
    5. In the Report - Parameters dialog that appears,  click Add. A parameter, ReportParameter1, is added.
    6. 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.  
    7. 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.   

    1. On the Choose Data Source Type screen of the wizard, select SQLite and click Next.
    2. 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.
    3. Click Test Connection to test the connection.
    4. Then click the Next option and configure the dataset by adding a valid query.
    5. Enter OrdersDataset into the Name and an SQL query like the following into the text box:
      Dataset Query
      Copy Code
      SELECT * FROM Orders
      
    6. Click Next to proceed to the final screen of the Report Wizard.
    7. Review the summary of the report and click Finish to successfully add the report with the JSON data source.  

    Design Master Report Layout


    Master Report Layout at Design
    (Design view of Master Report)
    1. Drag and drop the List data region onto the design area of the report.
    2. Click Property dialog to open the List dialog.
    3. 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.
    4. Click OK to close the dialog.
    5. 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
    6. Drag and drop the Subreport control onto the List data region as shown.
    7. In the Properties window, set the ReportName property to the detail report's name (e.g., subreport-details.rdlx).
    8. To pass the parameter from master report to details report, go to Parameters property and click the ellipses next to '(Collection)'.
    9. 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.
    10. Click OK to close the dialog.
    11. To add the report title, drag and drop a TextBox control above the List data region.
    12. Click inside the text box and enter the text 'Employee Orders Report (Master-Detail Report)'.    
    13. Improve the appearance of the report and preview.
    See Also