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 AdventureWorks database. The detail report displays product names and numbers. A Report Parameter is used to filter the detail report on product category.
Create a new class library named "MasterDetail" to contain the reports.
Add a new Telerik Report item to the project via Add New item - Reporting - Telerik Reporting [VERSION] Wizard - Blank Report, and name it DetailReport.
Click on the report selector (upper left corner of design surface) to select the report.
Navigate to its DataSource property, open it, select "Add New Data Source" and select SqlDataSource Component.
Setup the data connection to the AdventureWorks database, save it so it can be used later when creating the master report and click Next. 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
- Remove the page header and page footer sections. Open the Data Explorer and add the ProductNumber and Name fields to the detail section of the report.
The detail report should now look something like this in the designer.
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 record and the detail report prints all products that have that ProductCategoryID.
In the Property Window navigate to the ReportParameters property and click the ellipses.
In the ReportParameter Collection Editor click the Add button. In the Name property for the parameter enter ProductCategoryID. Enter zero for the Value property.
In the Property Window navigate to the Filters property and click the ellipses.
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 the report parameter we created in earlier step: =Parameters.ProductCategoryID.Value.
Click the OK button to close the dialog.
The master report will contain only a simple listing of product categories.
Add a new report item to the project and name it MasterReport.
The Report Wizard will display automatically, when you select Telerik Report [VERSION] Wizard - Band Report Wizard.
On Choose Data Source page of the wizard, click Add New Data Source button and select SqlDataSource Component. On the Choose Your Data Connection page of the wizard, select the saved database connection you created for the detail report. Click the Next button.
Enter the SQL statement below and click the Next button.
SELECT ProductCategoryID,Name FROM Production.ProductCategory
- 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.
This next set of steps ties both reports together using a SubReport to display the detail and passing the current ProductCategoryID from each record 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.
Resize the detail section to create some vertical room for a SubReport item.
Drag a SubReport from the Toolbox to the detail section of the report.
In the Properties Window for the SubReport, open the ReportSource dialog, select Type name (TypeReportSource) and set it to the DetailReport. Note that you should build the project first in order the type(s) to appear in the wizard.
Click the Edit Parameters button that would display the Edit Parameters dialog.
Click the New button to define a parameter.
Set the Parameter Name to ProductCategoryID and the parameter value to =Fields.ProductCategoryID.
Click the OK button to close the parameters dialog and click OK once again to close the Report Source dialog.
Click the Preview button to preview the MasterReport. Notice that product numbers and names from the detail report display under each product category from the master report.
The same report layout can be created with the Standalone Report Designer, where sub reports can be specified by path to a TRDX file or by directly placing the sub report's XML in the provided SubReport.ReportSource editor.