New to Telerik Reporting? Download free 30-day trial

SubReport Item Overview

The SubReport item enables you to display reports within reports, and serves as a container, similar to the report sections, growing in size depending on its children.

The following screenshot shows a SubReport item at design-time, allowing you to compose complex reports from various report sources. The data for each SubReport can be completely different, for example, you can combine a product listing, a sales summary, and a list of sales people each in their own sub-report with each sub-report drawing its data from a different source. You can also pass parameters to the SubReport by using the Edit Parameters collection editor.

SubReport item in the Report Designer

Defining the Parameters

To set up the SubReport:

  1. Click the report item you want to change. The selected SubReport properties are listed in the Property Browser.
  2. In the ReportSource property, click the Edit Collection (…) button. As a result, the Load a Report From window opens.
  3. Click the Edit Parameters button to add a parameter. As a result, the Edit Parameters window opens.
  4. Click the New button to add a new parameter mapping.
  5. Assuming you have assigned the ReportSource property, the Parameter Name drop-down list will contain the names of parameters defined in the sub-report. Select a Parameter Name from the combo-box to set the target for this parameter.
  6. The Parameter Value combo-box allows you to directly enter the value, create an <Expression> or a <New Report Parameter>.
  7. When you are done, click OK.

The following image shows the end result.

A SubReport with set parameters

Setting the Report Source

To specify a sub-report for a SubReport item, you need a report source object.

The SubReport enables you to set up the report source either by using a Telerik Report Designer tool or programmatically.

Using a Report Designer

To set the report source of the SubReport item by using a Telerik Report Designer:

  1. In the Design view, right-click a SubReport item to which you want to set a report source and click Properties.
  2. In the Properties of the item, click ReportSource. As a result, a Load a Report from dialog appears. Select a ReportSource.
  3. Select the type of the report source you will use to specify a report. For the purposes of this example, click the Instance Report Source option and select the report that will serve as the detail report.
  4. To specify the parameters for the report , click the Edit Parameters button. As a result, the Edit Parameters dialog appears. Click New.
  5. In the Parameter Name column, select the name of a report parameter in the detail report. In the Parameter Value, type or select the value to pass to the parameter in the detail report.

Defining Programmatically

The following snippet demonstrates how to set the report source of the SubReport programmatically.

var instanceReportSource = new Telerik.Reporting.InstanceReportSource();

// Assigning the Report object to the InstanceReportSource
instanceReportSource.ReportDocument = new Telerik.Reporting.Examples.CSharp.Invoice();

// Adding the initial parameter values
instanceReportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber", "SO43659"));
Dim instanceReportSource As New Telerik.Reporting.InstanceReportSource()

' Assigning the Report object to the InstanceReportSource
instanceReportSource.ReportDocument = New Invoice()

' Adding the initial parameter values
instanceReportSource.Parameters.Add(New Telerik.Reporting.Parameter("OrderNumber", "SO43659"))

Due to the format of the produced reports, the Standalone Report Designer includes only XmlReportSource and UriReportSource options.

The Visual Studio Report Designer provides the report sources options.

If you are using the HTML5 or the Silverlight Report Viewer to preview the report, the main report will be rendered in HTML or XAML respectively and loaded on the client. The sub-report is considered as part of the main report content and its report source will be internally resolved without additional calls to the Reporting REST service (Reporting WCF Service respectively).

The property DataSource of the SubReport item

The property was introduced with R3 2022 SP1 (16.2.22.1109).

It enables direct feeding of the inner report with data from the main report. When the property is set, its data will be used when processing the inner report instead of the data that is set up in the definition of the inner report.

All the data sources supported in the DataSource property are applicable as a value of this property.

A common scenario would be to feed the inner report with data coming from the data context of the SubReport item. To do this, define a Binding to bind the DataSource property to a data field.

For example, define a Binding with Path DataSource and Expression =Fields.InvoiceRows to link the inner report DataSource to the collection with the invoice rows from the main report DataSource.

Considerations and Known Limitations

When working with the SubReport item, note the following considerations:

  • Page sections are not related to the report itself, but are relative to the paper or screen. Therefore, page sections of nested or detail reports are ignored and only the page sections of the main report are visible.
  • To render page sections that appear on each page, similar to page sections, consider using an unbound group (no grouping criteria specified) and set the PrintOnEveryPage property of its sections to True. Note that you cannot use the PageCount and PageNumber global objects in group sections.
  • To remove blank vertical space in the detail section of a SubReport, set the Height of the SubReport.ReportSource DetailSection to the height of the highest item.
  • Sections can grow to accommodate their children but cannot shrink to hide empty space. To make the dtail section shrink only at runtime, set the Height property of the DetailSection in the report constructor. Place the Height property assignment code right after the IntializeComponent() method call.

Next Steps

See Also

In this article