New to Telerik Reporting? Download free 30-day trial

How to hide a SubReport with no data

Environment

Product Progress® Telerik® Reporting

Description

Sometimes you would like to hide a sub-report if there is no data to display inside.

By default the SubReport item inside the main report would occupy the preserved (design-time) space even if its content is empty.

The Detail section is rendered for each data record, so if there is no data, there will be no Detail section in the sub-report. However, the sub-report's ReportHeader/ReportFooter section (if any) would still be rendered.

Solution

Forcing the SubReport item not to occupy space in the main report when empty

To mimic hiding of the SubReport item inside the main report, you could set its height to '0' (zero). This way it will not occupy space when there is nothing to render. However, when there is data in the sub-report, it will grow automatically to occupy the needed space. Setting the height of the SubReport item to '0' would make it invisible in the report designer. If you need to select it, you could use the Report Explorer.

Forcing the sub-report referenced by the SubReport item to render blank/empty when there is no data

  • When the sub-report's data source is not directly dependent on the main report's data source, simply hiding the sub-report's ReportHeader/ReportFooter when there is no data would do. You could use Bindings to set the ReportHeader/ReportFooter section Visible property. For example:

    1. Select sub-report ReportHeader/ReportFooter Properties -> Bindings -> click on the ellipses to open the Bindings editor
    2. Click New to add new Binding to the ReportHeader/ReportFooter section
    3. Under Property path choose Visible
    4. Under Expression type:

          = Count(Fields.SomeFieldValue) > 0
      
  • When the sub-report's data source is directly dependent on the main report's data source, i.e. it is set (using Bindings) with an expression like:

        = ReportItem.DataObject
    

    you can use another Binding (also directly on the sub-report) to set its Visible property to an expression evaluated to True only when the sub-report data is not null/empty. For example, let's assume that 'SomeFieldValue' is a single string passed from the main report to the sub-report:

    1. Select sub-report Properties -> Bindings -> click on the ellipses to open the Bindings editor
    2. Click New to add new Binding to the sub-report
    3. Under Property path choose Visible
    4. Under Expression type:

          = ReportItem.DataObject.SomeFieldValue <> ""
      

Notes

The suggested approach assumes that the sub-report has a data source (that could return empty data set) assigned directly to its DataSource property. If the sub-report DataSource is null the approach will not work as expected.

In this article