Telerik Reporting

The following walk through demonstrates how to create a Master-Detail report using a SubReport report item to contain detail data. The master report data in this example consists of product categories from the AdventureWorksT database. The detail report displays product names and numbers. A Report Parameter is used to filter the detail report on product category.

Create the Detail Report

  1. Create a new class library named "MasterDetail" to contain the reports.

     

  2. Add a new Telerik Report item to the project and name it DetailReport.cs.
  3. The Report Wizard will display automatically. Accept the wizard default values until you reach the Choose a data connection page. In the Choose a Data Connection page click the New Connection button.
  4. The Add Connection dialog will display. In the Add Connection dialog:
    • Make sure the Data source is "Microsoft SQL Server". Set the Server name to "LOCALHOST\SQLEXPRESS". 
    • Verify that for "Log on to the server" has "Use Windows Authentication" selected.
    • For "Connect to a database" under "Select or enter a database name" choose the  AdventureWorks database (this database is installed along with Telerik Reports).
    • Click the OK button to close the Add Connection dialog.

    Add Connection Dialog

  5. In the Choose Your Database Connection page note the name of your connection for use in later creating the master report. Click the Next button.
  6. In the Choose Your Database Objects page enter the following SQL statement and click the Next button.
    CopySQL
    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
  7. In the Design Data Layout page of the wizard select "ProductNumber" and "Name" fields using the Detail button.

  8. Proceed through the remaining pages of the Report Wizard, accepting the default values. Click the Finish button to close the Wizard.
  9. Right click next to the report designer and un-select the Page Header, Page Footer and Report Header so that only the detail section remains.

    The detail report should now look something like this in the designer.

Configure the Report Parameter and Filter

This next set of steps creates a report parameter and a filter that uses the report parameter. The master report passes in the current ProductCategoryID for each row and the detail report prints all products that have that ProductCategoryID.

  1. In the Property Window navigate to the Report.ReportParameter property and click the ellipses.
  2. In the ReportParameter Collection Editor click the Add button. In the Name property for the parameter enter "ProductCategoryID". In the Value property for the parameter enter a zero.

  3. In the Property Window navigate to the Report.Filters property and click the ellipses.
  4. 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 select "<Expression>".

  5. In the Edit Expression dialog locate the Report Parameters from the list of expression elements. Double-click ProductCategoryID so that the expression in the upper window reads "= Parameters.ProductCategoryID".
  6. Click the OK button to close the dialog.

Create the Master Report

The following steps create the master report. The master report will contain only a simple listing of product categories.

  1. Create a new report item in the project and name it MasterReport.cs.
  2. In the report wizard accept the default values until you reach the Choose a Data Connection page. Select the database connection you created earlier from the drop down list. Click the Next button.
  3. In the Choose your Database Objects page enter the SQL statement below and click the Next button.
    CopySQL
    SELECT ProductCategoryID,Name FROM Production.ProductCategory
  4. In the Design Data Layout  page of the wizard select the "Name" column and click the Next button. Continue taking the defaults until you finish the Wizard.

Configure the SubReport

This next set of steps tie the two reports together using a SubReport to display the detail and passing the current ProductCategoryID from each row of the master report to the detail. The detail report uses the parameter to filter the data to only products for the specified product category.

  1. Drag the sizing bar at the base of the detail section down to create some vertical room for a SubReport item.
  2. Drag a SubReport from the Toolbox to the detail section in the report designer. The project should look something like the example screen-shot below.

  3. In the Properties Window for the SubReport set the ReportSource property to the detail report.
  4. Locate the Parameters property for the SubReport and click the ellipses. The Edit Parameters dialog will display.
  5. Click the New button to define a parameter.
  6. Set the Parameter Name to ProductCategoryID and the Parameter Value to "=Fields.ProductCategoryID".
  7. Click the OK button to close the dialog.

    Build the report and click the Preview button to review the completed results. Notice that product numbers and names from the detail report display under each product category from the master report.