New to Telerik Reporting? Download free 30-day trial

SubReport

A SubReport is a report component that allows you to embed one report inside another report. This lets you create complex report layouts, display hierarchical data relationships, and build reusable report components that can be shared across multiple reports.

SubReports act as containers that automatically adjust their size based on the content of the embedded report. You can use SubReports to create:

  • Master-detail relationships—Display related data in a parent-child format (for example, customers and their orders).
  • Reusable components—Create shared headers, footers, or report sections that can be used across multiple reports.
  • Complex layouts—Combine different data sources and report structures within a single report.
  • Hierarchical data—Show nested data relationships with proper grouping and organization.

The next video demonstrates how to create master-detail reports by using SubReports in the Telerik Web Report Designer:

Prerequisites

Before working with SubReports, ensure you have:

  • Created and configured data sources for both master and child reports.
  • Planned your data relationships and report hierarchy.

Creating Master-Detail Reports with SubReports

The following example demonstrates how to create a master-detail report using SubReports. The master report (CategoriesProducts.trdp) contains a table with Northwind Categories data. The SubReport (ProductsReport.trdp) displays Northwind Products records filtered by the respective CategoryID.

To follow along with the steps below, you need access to an instance of the Northwind database for Microsoft SQL Server.

Step 1: Building the Child Report

  1. Start with a blank report (ProductsReport.trdp) that will serve as the child report. Select the header and footer sections and delete them.

    SubReport ><

  2. Add a new SQL Data Source populated with the Northwind.Products table:

    Here is the SQL query that selects the respective data:

    SELECT
        [dbo].[Products].[ProductID], 
        [dbo].[Products].[ProductName], 
        [dbo].[Products].[Discontinued], 
        [dbo].[Products].[SupplierID], 
        [dbo].[Products].[CategoryID], 
        [dbo].[Products].[QuantityPerUnit], 
        [dbo].[Products].[UnitPrice], 
        [dbo].[Products].[UnitsInStock], 
        [dbo].[Products].[UnitsOnOrder], 
        [dbo].[Products].[ReorderLevel]
    FROM [dbo].[Products]
    
  3. Set the DataSource of the report using the created SQLDataSource:

    Report DataSource ><

  4. From the Components tab, drag two TextBox report items to the Detail section:

    4.1. Select each of the TextBoxes.

    4.2. Bind the the Value property of the TextBoxes to the ProductName and UnitPrice fields respectively.

    4.3. Use the Expression dialog to set the desired field.

    Bind Product Fields ><

  5. Preview the report to verify that all Products are listed.

  6. Add an integer report parameter called ProductCategoryID which you will use to filter by product:

    Create Report Parameter ><

  7. Update the SELECT query of the added SQLDataSource and add a WHERE clause using an SQL parameter (which is mapped to the previously created report parameter):

    SELECT
        [dbo].[Products].[ProductID], 
        [dbo].[Products].[ProductName], 
        [dbo].[Products].[Discontinued], 
        [dbo].[Products].[SupplierID], 
        [dbo].[Products].[CategoryID], 
        [dbo].[Products].[QuantityPerUnit], 
        [dbo].[Products].[UnitPrice], 
        [dbo].[Products].[UnitsInStock], 
        [dbo].[Products].[UnitsOnOrder], 
        [dbo].[Products].[ReorderLevel]
    FROM [dbo].[Products]
    WHERE [dbo].[Products].[CategoryID]=@sqlParamCategoryId
    

    Update SQL Select ><

  8. Save the report (ProductsReport.trdp). You will use it as a child report.

Step 2: Building the Master Report

  1. Create a new blank report (CategoriesProducts.trdp).

  2. Add a new SQL Data Source filled with the Northwind.Categories table:

    SELECT
        [dbo].[Categories].[CategoryID], 
        [dbo].[Categories].[CategoryName], 
        [dbo].[Categories].[Description], 
        [dbo].[Categories].[Picture]
    FROM [dbo].[Categories]
    
  3. Select the report's Detail section and use the Table Wizard to add a table bound to the just added SQLDataSource:

    Create Categories Table ><

  4. Select the Picture header and change its text to Products.

  5. Select the data cell bound to the Picture field ([=Fields.Picture]) and add a SubReport item by selecting it from the Components tab:

    Adding SubReport ><

  6. Specify the Inner Report for the SubReport item and select the Uri option that refers to the previously created ProductsReport.trdp:

    Setup UriReportSource ><

  7. Set up the relation between the parent and child reports:

    7.1. Adjust the parameters.

    7.2. Link the SubReport parameter (ProductCategoryID) with the master report's CategoryID field.

    Setup ProductCategoryID Report Parameter ><

  8. Save the changes and preview the master report. You will see all categories listed with the respective products for each category:

    Master-Detail hierarchy ><

See Also

In this article