Telerik Reporting R1 2017

How to: Create a Master-Detail Report Using a Table

The following walkthrough demonstrates how to create a Master-Detail report using a Table report item to contain the detail data. The master report data in this example consists of product categories from the AdventureWorks database. The detail table displays product names and numbers.  The ReportItem.DataObject property is used to filter the detail table on product category.

Create the Master Report

The master report will contain only a simple listing of product categories.

  1. Create a new Telerik Report Library to contain the report.

  2. The Choose Report Type dialog opens. Select Band Report Wizard and enter a name for the report class.

  3. On the Choose Data Source page of the Band Report Wizard, click the Add New Data Source button and select the SqlDataSource Component. On the Choose Your Data Connection page of the wizard, setup the data connection to the AdventureWorks database, save it so it can be used later when creating the Table item, and click Next.

  4. Enter the SQL statement below and click the Next button.

    SELECT ProductCategoryID, Name FROM Production.ProductCategory
  5. In the Design Data Layout page of the wizard add the Name column to the detail section and click the Next button. Continue taking the defaults until you finish the Wizard.

Create the Detail Table

  1. Resize the detail section to create some vertical space for the Table item.

  2. Drag the Table Wizard item from the Visual Studio Toolbox to the detail section of the report.

  3. On the Choose Data Source page of the Table Wizard, click the Add New Data Source button and select the SqlDataSource Component. On the Choose Your Data Connection page of the wizard, select the already created data connection and click Next.

  4. Enter the following SQL statement and Finish the DataSource wizard.

    SELECT 
            P.Name,ProductID,ProductNumber,PC.ProductCategoryID
    FROM 
            Production.Product P,
            Production.ProductSubcategory PS,
            Production.ProductCategory PC
    WHERE 
            P.ProductSubcategoryID=PS.ProductSubcategoryID
            AND PS.ProductCategoryID=PC.ProductCategoryID
  5. In the Arrange Fields page of the Table Wizard add the ProductNumber and Name fields to the Table Columns and click the Next button. Continue taking the defaults until you finish the wizard.

Configure the Table Filter

This next set of steps creates a filter that uses the ReportItem.DataObject property to pass in the current ProductCategoryID for each record and the detail table prints all products that have that ProductCategoryID.

  1. Select the Table item.

  2. In the Property Window navigate to the Filters property and click the ellipses.

  3. Click the New button to create a new filter. In the Expression drop down for the filter select =Fields.ProductCategoryID. Leave the operator at the default equals ("=") sign. In the Value property drop down enter the expression: =ReportItem.DataObject.ProductCategoryID.

    Master Detail Table 0001
  4. Click the OK button to close the dialog.

Click the Preview button to preview the report. Notice that product numbers and names from the detail table display under each product category from the master report.

Master Detail Table 0002
Note Note

The same report layout can be created with the Standalone Report Designer.