DataSource binding for SubReport

7 posts, 0 answers
  1. Alexey
    Alexey avatar
    3 posts
    Member since:
    Aug 2011

    Posted 16 Jan 2012 Link to this post

    Hi,

    I have the subreport inside a list and I want to send items from the list's data source to this subreport. I added binding ReportSource.DataSource=Field.Group to my subreport and put this subreport into a panel inside the list. 

    What's my next step? How can I access this data (Field.Group) within my subreport and display it?

    Regards,
    Alex.
  2. Elian
    Admin
    Elian avatar
    435 posts

    Posted 19 Jan 2012 Link to this post

    Hi,

    If the binding is successful, then inside the sub-report you use the fields as normal. Fields.FieldName. If for example your group has properties: GroupName and GroupNumber, then you can call them by Fields.GruopName and Fields.GroupNumber.

    For reference I have attached a sample project showing the usage of sub-reports and data-binding. 

    All the best,
    Elian
    the Telerik team

    Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  3. Tomas
    Tomas avatar
    92 posts
    Member since:
    Jun 2010

    Posted 06 Aug 2012 Link to this post

    Hi Elian,

    How can I accomplish the datasouce binding using Q2 2012?
    Because this clearly doesn't work anymore:
    this.subReport1.Bindings.Add(new Telerik.Reporting.Binding("ReportSource.DataSource", "=ReportItem.DataObject.Departments"));

    Tomas
  4. Elian
    Admin
    Elian avatar
    435 posts

    Posted 07 Aug 2012 Link to this post

    Hello Tomas,

    Since the introduction of the new Report Sources things have changed a bit. 
    In your case, one option to get the same result would be to move the binding from the main report, to the detailed report. Since the sub-report is a child of the main report it can access it's elements (including the data-elements).  For example this binding placed in the detailed report, would have the same output.
    this.Bindings.Add(new Telerik.Reporting.Binding("DataSource", "=ReportItem.Parent.DataObject.Departments"));
    You can also create a user function that will assign the ReportSource to the SubReport item. 

    public static ReportSource GetReportSource(object dataObject)
    {
        var report = new DetailedReport();
        report.DataSource = dataObject;
        return new InstanceReportSource { ReportDocument = report };
    }
    and the binding in the main report will be:
    this.subReport1.Bindings.Add(new Telerik.Reporting.Binding("ReportSource", "= GetReportSource(ReportItem.DataObject)"));
     
    Regards,
    Elian
    the Telerik team

    BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

  5. Tomas
    Tomas avatar
    92 posts
    Member since:
    Jun 2010

    Posted 08 Aug 2012 Link to this post

    Thank you Ellan. My reports works as expected again.

    Tomas
  6. Karl Wilkens
    Karl Wilkens avatar
    206 posts
    Member since:
    Oct 2012

    Posted 06 Jan 2013 Link to this post

    Hi,

    REALLY struggling with this and having spent a day reading various posts, links to dead non functioning help pages and the like, conclude your documentation is very weak on the subject.

    In CodeBehind in the master report we have a sub report and want to assign it to a data table that is part of a 3 table set. I have sub reports setup for each table, and corresponding NeedDataSource handlers in the main report code behind, but only the first NeedDataSource fires. 

    I read somewhere that if the goal is to have multiple sub reports, then each part of the report needs to have its own NeedsdataSource. Unfortunately, only the main report's NeedDataSource event fires. The sub report NeedDataSource events never fire.

    ANY help appreciated. Judging by all the posts, this is an area that needs some work.
  7. Steve
    Admin
    Steve avatar
    10940 posts

    Posted 08 Jan 2013 Link to this post

    Hi Karl,

    As documented here (Using the NeedDataSource event to connect data) NeedDataSource of a Data Item (SubReport in your case) is only fired if it still has no data source attached. Have you double checked that the reports that you specify as SubReports do not have DataSource property set?

    Regards,
    Steve
    the Telerik team

    HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Back to Top