This is a migrated thread and some comments may be shown as answers.

SubReport DataBinding on Condition/Visibility

1 Answer 336 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 15 Jul 2014, 09:14 AM
Hello,

I have a master report which contains many subreports. Every subreport uses its own datasource with its own design. Their visibility is controlled via the binding property of the subreport.

It looks like all subreports are bound to their SqlDatasource regardless of if they're visible or not. Is there an easy way to bind only the subreports to their datasources which are visible?

I'm using the Report Designer for Visual Studio.

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 18 Jul 2014, 08:49 AM
Hello Dennis,

Even though report items are not visible, they are still going to be processed by the reporting engine. In order to work around this your only option is to remove the items from the report definition based on the user input. This requires programmatic report generation. In general, the fastest way to do this is to to create the desired report layout in the Visual Studio Report Designer and use the code it automatically generated in the .Designer.cs file as a template for dynamic report generation. In this undertaking you may also find useful the Programmatic Control of Reports help articles on the topic and the Reporting API Reference.

We have another idea on how you can improve the performance of the report. The idea is that when a data item is hidden in the report (binding setting Visible=False), it does not need to retrieve data in your particular scenario. Thus, if you apply filtering on the data source level based on report parameters and data source parameters, you will be able to speed up the report noticeably.

For example, there is a SubReport data item in the Detail section of the report. This data item has the following binding set to it:

Visible =Parameters.ShowSubReport.Value>0

Let's say the SubReport uses an SqlDataSource. Thus, if the SubReport is hidden, we can "tell" the SqlDataSource to stop retrieving data from the database by passing a report parameter from the main report to the SubReport. We can achieve that by adding a new parameter to the SqlDataSource.Parameters collection and set its value to the ShowSubReport report parameter value. Then in the SqlDataSource.SelectCommand you can add a WHERE clause which will filter the selected rows exactly as in the SubReport binding:

WHERE @ShowSubReport>0

If you are using a stored procedure you will need to alter the stored procedure to receive a parameter.

If you apply this method to all of the data items in the report which can be hidden at some point we guess that the report will run faster, since it doesn't need to process all of the data, but just a part of the data that will be visible in the report.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Dennis
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or