Telerik Reporting - Tips and Tricks

by Reporting Team | Comments 6
What better source for tips and tricks for your beloved Reporting product, than a blog spot right from the kitchen where the product is ‘mixed’. As of this post, we would like to start a small series of tips and tricks that make a developers’ life sweeter. We’re not going to discuss general topics, so if you’re looking for answers for one of those questions – please review our documentation and our forums.
As you can guess, the sub-report item, which lets you display one report within another report is widely used in Telerik Reporting.  It lets you compose complex reports from disparate report sources and the data for each sub-report can be completely different. With its help you can create the very much exploited master-detail report scenarios with ease. Wiring up report parameters and accessing the sub-report’s report is straightforward, but a question arises - what should we do if there is no data to be shown in the sub-report under some conditions. Well, we can check if it has data and if it does not contain any - hide it, so it does not take up any unnecessary space and mess up the master report layout . We’re going to use the subreport_ItemDataBound eventhandler for this purpose:

private void subReport1_ItemDataBound(object sender, System.EventArgs e)
{
    Processing.SubReport subReport = (Processing.SubReport)sender;
    Processing.Report report = (Processing.Report)subReport.InnerReport;
    subReport.Visible = Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(report, "detail", true).Length > 0;
}

The "detail" parameter is the name of the detail section of the report set as Report Source for the sub-report item.

Hope this helps!

About the author

Stefan Tsokev

Stefan Tsokev

is Enterprise Support Officer for the Telerik Reporting division. He has been working for the company since 2005, when he started out as a regular support officer for one of the ASP.NET AJAX teams and he has been through the position of Technical Support Director as well. Stefan’s main interests outside the .NET domain include rock music, playing the guitar and swimming.

6 Comments

Ismael
Thank you!!
Patrick
Indeed it did, thanks!
Damien Cameron
Where would this code be placed? Sorry just starting to work in this structure, and I need a small bit of guidance.
If it goes in the (nameofreport).Designer.cs, then I have a small problem.
The Processing keyword is unrecognized.
Steve
You can either add using for Telerik.Reporting.Processing or manually enter the full namespace: Telerik.Reporting.Processing.SubReport. We've also changed the API in the latest version, so I've updated the article accordingly.
Carla b
Error 1 The type or namespace name 'ElementTreeHelper' does not exist in the namespace 'Telerik.Reporting.Processing'
Steve
Carla, you must be using version prior to Q2 2012. As explained in my previous post, the code in the article has been updated according to the latest changes. If you can't figure out how to accomplish this with your version, open a support ticket.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by Reporting Team - or - read latest articles in Developer Tools