Sub Report Datasource is Null

5 posts, 0 answers
  1. Amine
    Amine avatar
    3 posts
    Member since:
    Nov 2013

    Posted 13 Mar 2015 Link to this post

    Hello, 

    I am working on a report where i have a sub report ,

    i implemented the NeedDataSource  event  of the SubReport object inside the main report,
    Also i  set the ReportSource property to object instance of my Sub report.

    The sub report is displayed correctly (for example setting "=Fields.Name"   in a text box returns the right value)

    I need to access to the DataSource property inside the sub report  from C#  (this.dataSource) bu it is always null.


    Thanks  in Advance 
    Amine
  2. Amine
    Amine avatar
    3 posts
    Member since:
    Nov 2013

    Posted 16 Mar 2015 in reply to Amine Link to this post

    Finally , i found a sollution.

    the current object is under : subReportItem.DataObject.RawData

  3. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 16 Mar 2015 Link to this post

    Hello Amine,

    If  you need to bind the sub report to the same data as the master report, please use the approach discussed in How to bind the DataSource of a SubReport in the designer.


    We will appreciate it if you elaborate on the scenario and reason to access the sub report's DataSource in code.

    Regards,
    Stef
    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.

     
  4. Amine
    Amine avatar
    3 posts
    Member since:
    Nov 2013

    Posted 17 Mar 2015 in reply to Stef Link to this post

    Hello Stef, Thanks for the reply. 

    Actually this is not exactly my scenario. However i found a solution as i posted before. but this is the complete scenario : 

    I have a main report (MainReport) containing a subreport(FirstSubReport) witch also conatins a subreport(SecondSubReport) 
    in the main report i  added a subreport and implemented its needsDataSource event : 

    private void FirstSubReport_NeedDataSource(object sender, EventArgs e)
    {
    Telerik.Reporting.Processing.SubReport subReportItem = sender as Telerik.Reporting.Processing.SubReport;
    subReportItem.InnerReport.DataSource = ((MyBusinessObject)this.DataSource).FirstCollection;
    }

    Then inside the firstSubreport i added a sub report object for the Second one and tried to implement the needsDataSource  as i did for the first one: 

    private void SecondSubReport_NeedDataSource(object sender, EventArgs e)
    {
    Telerik.Reporting.Processing.SubReport subReportItem = sender as Telerik.Reporting.Processing.SubReport; subReportItem.InnerReport.DataSource = ((FirstObject)this.DataSource).SecondCollection;
    }

    so my problem was that this.DataSource was null and The solution was to use subReportItem.DataObject.RawData instead:

    private void SecondSubReport_NeedDataSource(object sender, EventArgs e)
    {
    Telerik.Reporting.Processing.SubReport subReportItem = sender as Telerik.Reporting.Processing.SubReport;
    subReportItem.InnerReport.DataSource = ((FirstObject)subReportItem.DataObject.RawData).SecondCollection;
    }


    And it worked as expected..

    Regards 
    Amine
     
  5. Nasko
    Admin
    Nasko avatar
    1049 posts

    Posted 20 Mar 2015 Link to this post

    Hello Amine,

    What you have found out is correct and is also described in the Understanding Events help article:

    "The sender parameter of the event handler methods is in fact the processing report item...

    Be very careful when working inside event handlers. If by mistake you modify the report item (the private field of the report class, i.e. this.textBox1) instead of its processing counterpart (the sender argument), all subsequent processing items will be modeled after the modified reporting item
    ."

    The text above means that it is not correct to use this.DataSource inside events. You should always get a reference to the desired report item from the sender argument.

    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.

     
Back to Top