New to Telerik Reporting? Download free 30-day trial

SubReport

The SubReport report item lets you display one report within another report. It is a container item just like the report sections and grows depending on its children. The screenshot shows a SubReport report item at design-time. This allows you to compose complex reports from disparate report sources. The data for each SubReport can be completely different. For example you could combine a product listing, a sales summary and a list of sales people each in their own sub reports, with each sub report getting data from a different source. You can also pass parameters to SubReports using the Edit Parameters collection editor.

Data Items cannot be used in page sections, because the latter are processed after the report data has been processed. At this moment the report data source is not available anymore.

Page sections are not related to the report itself, but are relative to the paper or screen. Thus page sections of nested/detail reports are ignored and only the page sections of the main report are visible.In order to have sections that repeat on every page similar to page sections, consider using an unbound group (no grouping criteria specified) and set the PrintOnEveryPage property of its sections to True. Be aware that you cannot use PageCount and PageNumber global objects in group sections.

Height Issues

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 tallest item. Sections can grow to accommodate their children but cannot shrink to hide empty space. If you want the detail section to shrink only at runtime you can set the Height property of the DetailSection in the report constructor. Place the Height property assignment code just after the IntializeComponent() method call.

Passing Parameters to a SubReport

  1. Click the subreport item that you want to change. The selected subreport properties are listed in the Property Browser.

  2. In the ReportSource property, click the Edit Collection (…) button. Load a Report From window opens.

  3. Click Edit Parameters button to add a parameter. 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 subreport report. Select a Parameter Name from the combobox to set the target for this parameter. from the combobox to set the target for this parameter.

  6. Parameter Value combobox allows you to enter value directly, create an "<Expression>" or a "<New Report Parameter>".

  7. When you are done, click OK.

How to Set ReportSource for SubReport

This article includes details how to specify a sub report for a SubReport item. You will need a Report Source object.

Setting the Report Source through the Report Designer

  1. In Design view, right-click a SubReport item to which you want to set a report source and click Properties.

  2. In the item's Properties , click ReportSource.

  3. A "Load a Report from" dialog appears which allows you to select a ReportSource.

  4. Select the type of report source you would use to specify a report. For this example we would use Instance Report Source , click that option and select the report that would serve as detail report.
    If you have to specify parameters for the report, follow the next step.

  5. Click Edit Parameters button - Edit Parameters dialog appears. Click New. 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.

Setting the Report Source 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"))

The Standalone Report Designer includes only XmlReportSource and UriReportSource options due to the format of the produced reports. In Visual Studio Report Designer you can use all available Report Sources.

If the report will be displayed in an HTML5 Viewer or Silverlight ReportViewer, the main report is rendered in HTML (XAML respectively) and it is loaded at the client. The sub report is considered as a content of the main report and its Report Source is resolved internally, withouit additional calls to the Reporting REST service (Reporting WCF Service respectively).

See Also

In this article