The Definitive Guide to C# .NET Subreports in Your Web and Desktop Apps

MESCIUS inc.
MESCIUS inc.
Published in
9 min readAug 30, 2024

ActiveReports.NET is a powerful reporting tool that allows developers to design, customize, and integrate reports into their applications. One of the advanced features of ActiveReports is the ability to use subreports. Subreports can help create complex and hierarchical reports by embedding one report within another. In this blog post, we’ll explore:

  • What subreports are
  • Why they are useful
  • How to use them in the following types of ActiveReports:
  • RDLX Reports
  • Page Reports
  • Section Reports

What is a Subreport?

A subreport is a report embedded within another report. It allows for the inclusion of additional data or details that complement the main report without cluttering the main report’s layout. Subreports can be used to create master-detail reports, where the main report shows summary information and the subreport displays related, detailed data.

Why Use Subreports?

Subreports are beneficial for several reasons:

  1. Modularity: By breaking down complex reports into smaller, manageable subreports, you can simplify the design and maintenance process.
  2. Reusability: Subreports can be reused across multiple reports, saving time and effort.
  3. Detailed Data: Subreports allow you to include detailed information that supports the main report’s data, providing a comprehensive view of the information.
  4. Separation of Concerns: They help to separate different aspects of reporting, such as summary and detail, making the reports easier to understand and manage.

How to Use Subreports in RDLX Reports

In ActiveReports.NET, RDLX reports are based on the Report Definition Language (RDL), a standardized, XML-based schema for defining reports. RDLX reports are particularly suited for scenarios requiring complex data handling. These reports allow intricate data manipulation, extensive formatting options, and sophisticated expressions and functions. The flexibility and power of RDLX reports make them ideal for large-scale enterprise reporting, where detailed, dynamic, and data-driven reports are essential. Additionally, RDLX reports support a variety of data sources and enable the creation of interactive, drill-down reports that provide deeper insights into the data.

Simplified Steps to Add a Subreport in RDLX Reports:

  1. Design the Subreport: Create the subreport as a standalone RDLX file. Ensure it is designed to fit within the main report’s layout.
  2. Add a SubReport Control: In the main report, add a SubReport control from the toolbox to the desired location.
  3. Set Subreport Properties: Set the ReportName property of the SubReport control to the name of the subreport file.
  4. Pass Parameters (if needed): If the subreport requires parameters, you can pass them from the main report to the subreport through the SubReport control’s properties.

Full Tutorial: Adding a Subreport to an RDLX Report in ActiveReports.NET

Step 1: Create the Subreport

  1. Launch the ActiveReports Designer: Open the ActiveReports Designer from your development environment.
  2. Design Your Subreport: Create a new RDLX report file to serve as your subreport. Lay out the necessary data fields and controls. For instance, if your subreport will display detailed transaction data, ensure it contains the relevant table or list control to show these details.
  3. Save the Subreport: Save your subreport with a descriptive name, such as TransactionDetails.rdlx.

Step 2: Insert a SubReport Control into the Main Report

  1. Open the Main Report: Load your main RDLX report in the ActiveReports Designer.
  2. Add the SubReport Control: Drag and drop the SubReport control from the toolbox onto your main report’s design surface at the desired location, such as within a tablix or list control.
  3. Configure the Subreport Properties: With the SubReport control selected, set the ReportName property to the name of the subreport file (e.g., TransactionDetails.rdlx) in the Properties panel.

Step 3: Link Data and Parameters

  1. Set Up the DataSource for the Main Report: Ensure your main report is connected to the appropriate data source that contains the information needed to drive both the main report and the subreport.

2. Pass Parameters to the Subreport: If your subreport requires parameters (e.g., a TransactionID), configure these in the SubReport control’s properties. The Parameter Name should exactly match the name of the parameter set in the subreport, and the Parameter Value is what will be passed to that parameter.

Step 4: Preview and Finalize

  1. Preview Your Work: Switch to the Preview tab to check how the subreport integrates into the main report. Verify the data displays correctly and the layout appears as intended.
  2. Make Adjustments if Necessary: If the subreport isn’t displaying correctly, revisit the property settings and data connections to ensure everything is properly configured.

Step 5: Save and Deploy

  1. Save the Updated Report: Save the main report with all your changes.
  2. Deploy the Reports: Deploy both the main report and subreport to your application’s report server or include them in your application’s deployment package.

How to Use Subreports in Page Reports

Page Reports in ActiveReports.NET are designed with precision and print-ready output in mind. These reports provide absolute control over the layout, making them perfect for highly formatted documents, such as invoices, labels, or product catalogs, where the exact placement of elements is crucial. Page Reports support multiple page sizes and orientations, complex layout structures, and advanced formatting options. They are especially beneficial in scenarios where the visual presentation of the report is as important as the data itself. Page Reports ensure consistency in appearance across different devices and printers, making them an excellent choice for documents that need to maintain a professional and polished look.

Simplified Steps to Add a Subreport in Page Reports:

  1. Create the Subreport: Design your subreport as a standalone Page Report (.rdlx file).
  2. Insert the SubReport control: In the main Page Report, drag and drop the SubReport control from the toolbox to the desired location on the report.
  3. Link the Subreport: In the properties panel, set the ReportName property of the SubReport control to the subreport you created.
  4. Configure Data and Parameters: Ensure that data connections and parameters are properly configured to pass data from the main report to the subreport.

Full Tutorial: Adding a Subreport to a Page Report in ActiveReports.NET

Step 1: Design the Subreport

  1. Start the ActiveReports Designer: Open the ActiveReports Designer from your development tools.
  2. Create the Subreport: Design a new Page Report that will act as your subreport. Add the necessary controls and data fields to the report. For example, if your subreport is meant to show product details, include a table control that organizes this information.
  3. Save Your Subreport: Save the subreport file with a clear and descriptive name, such as ProductDetails.rdlx.

Step 2: Embed the Subreport in the Main Report

  1. Open Your Main Report: Open the primary Page Report in the ActiveReports Designer.
  2. Place the SubReport Control: Drag a SubReport control from the toolbox and drop it into the design area where you want the subreport to appear. This could be within a specific region of the report, such as a body section or a tablix.
  3. Link the Subreport: In the Properties window, set the ReportName property of the SubReport control to reference the subreport you created earlier (e.g., ProductDetails.rdlx).

Step 3: Pass Data and Parameters

  1. Ensure DataSource Configuration: Verify that the main report is linked to a data source that supplies all necessary data, including that required by the subreport.

2. Configure Parameters: If your subreport requires parameters (e.g., a ProductID), configure these in the SubReport control’s properties. The Parameter Name should exactly match the name of the parameter set in the subreport, and the Parameter Value is what will be passed to that parameter.

Step 4: Test and Refine

  1. Preview the Report: Click the Preview tab to see how the subreport appears within the main report. Ensure that the data is correct and that the subreport is properly integrated.
  2. Adjust if Needed: If there are issues with how the subreport displays, revisit the configuration settings, particularly focusing on data bindings and parameter passing.

Step 5: Save and Deploy

  1. Save the Report: Save your main report with the newly added subreport.
  2. Deploy Your Reports: Deploy both the main report and the subreport to your report server or embed them within your application’s deployment process.

How to Use Subreports in Section Reports

Section Reports offer a banded report model that is highly versatile and straightforward. They are ideal for reports with repeating sections, such as invoices, receipts, or statements, where a header, detail, and footer structure is commonly used. Section Reports are known for their ease of use and flexibility, allowing developers to quickly design reports with different sections for grouping and summarizing data. The banded layout of Section Reports supports a variety of data regions, including subreports, charts, and cross-tabs, making them a versatile option for a wide range of reporting needs. Their simplicity and robust feature set make Section Reports a popular choice for developers who need to create detailed and structured reports efficiently.

Simplified Steps to Add a Subreport in Section Reports:

  1. Design the Subreport: Create the subreport as a standalone Section Report (.rpx file).
  2. Add the SubReport Control: In the main Section Report, add a SubReport control to the appropriate section (e.g., Detail, GroupHeader, etc.).
  3. Set the Subreport Source: Set the ReportName property of the SubReport control to the subreport you created.
  4. Pass Data and Parameters: Ensure data and parameters are passed correctly from the main report to the subreport. This can be done through the SubReport control’s DataSource and Parameter properties.

Full Tutorial: Adding a Subreport to a Section Report in ActiveReports.NET

Step 1: Design the Subreport

  1. Launch ActiveReports Designer: Open the ActiveReports Designer from your development environment.
  2. Create and Layout the Subreport: Begin by creating a new Section Report that will function as your subreport. Design it by adding the necessary fields and controls. For example, if your subreport will display detailed sales data, include a data-bound control like a table or chart.
  3. Save the Subreport: Save your subreport with a name that reflects its purpose, such as SalesDetails.rpx.

Step 2: Integrate the Subreport into the Main Report

  1. Open the Main Section Report: Load your primary Section Report in the ActiveReports Designer.
  2. Add the SubReport Control: Drag the SubReport control from the toolbox into the appropriate section of your main report, typically within the Detail section or a group header/footer.
  3. Configure the Subreport Properties: Set the ReportName property of the SubReport control to the file name of your subreport (e.g., SalesDetails.rpx) in the Properties panel.

Step 3: Set Up Data and Parameters

  1. Confirm Main Report DataSource: Confirm that your main report is connected to the relevant data source. This data should include the information necessary for both the main and subreport.
  2. Pass Parameters to the Subreport: If your subreport requires parameters (e.g., SalesID), these should be configured in the SubReport control’s properties.
  3. Reference the Documentation:Section reports are a bit more complicated than RDLX and Page reports. If you are having trouble setting up your section report with a subreport and parameters, we suggest following the documentation instead of this basic high-level guide.

Step 4: Preview and Fine-Tune

  1. Preview the Combined Report: Switch to the Preview tab to check the integration of the subreport with the main report. Verify that all data is displayed correctly and that the report layout appears as expected.
  2. Refine if Necessary: If the subreport does not display as intended, revisit your property settings and data bindings to correct any issues.

Step 5: Save and Deploy

  1. Save the Final Report: Save the main Section Report with the embedded subreport.
  2. Deploy Both Reports: Ensure that both the main and subreport are deployed to your report server or included in your application’s deployment.

Conclusion

Subreports in ActiveReports.NET provide a flexible and powerful way to create comprehensive and detailed reports. By understanding how to implement subreports in RDLX, Page Reports, and Section Reports, you can leverage their full potential to enhance your reporting solutions. Whether you need to break down complex data into manageable sections or reuse report components across multiple reports, subreports are an essential tool in your reporting toolkit.

By following the steps outlined above, you can seamlessly integrate subreports into your ActiveReports.NET projects, creating professional and detailed reports that meet your business needs.

Originally published at https://developer.mescius.com on August 30, 2024.

--

--

MESCIUS inc.
MESCIUS inc.

We provide developers with the widest range of Microsoft Visual Studio components, IDE platform development tools, and applications.