Runtime ObjectDataSource is overwritten when refreshing report

2 posts, 0 answers
  1. Phil
    Phil avatar
    3 posts
    Member since:
    Feb 2012

    Posted 05 Sep Link to this post

    Hi,

    I am trying to set my report datasource at runtime but it always seems to be recreated each time the report is refreshed. Basically I need to pass some complex parameters into my object's constructor (meaning that using report parameters wont be sufficient as they aren't basic types). I'm using the WinForms viewer and Q1 2016 reporting.

                var report = new MyReport();
                var ds = new MyReportDataSource();
                var objDs = new ObjectDataSource(); // I want to be able to pass some complex parameters here to initialize the object - this is just a trivial example
                objDs.DataSource = ds;
                objDs.DataMember = "Text";
                report.DataSource = objDs;
                var reportSource = new InstanceReportSource();
                reportSource.ReportDocument = report;
                ctl_Report.ReportSource = reportSource;
                ctl_Report.RefreshReport(); // This causes the constructor of MyReportDataSource to be called again

     

    I have also tried setting the report.DataSource property to null, which causes the NeedDataSource event to fire - but this doesn't help as even if I set the datasource in the event callback, the constructor of MyReportDataSource gets called AGAIN when calling RefreshReport().

    Is there a way to "inject" data into the report without it explicitly calling the constructor of the ObjectDataSource's data member?

     

    Thanks,

    Phil

  2. Stef
    Admin
    Stef avatar
    3050 posts

    Posted 07 Sep Link to this post

    Hello Phil,

    In general, the purpose of the ObjectDataSource component is to provide data to the report in a declarative manner. The ObjectDataSource.DataSource should be the assembly qualified name or Type of the data access layer (class), where the reporting engine will use System.Reflection to create the instance of the class (by using the its default constructor) and to execute its  method specified by the ObjectDataSource.DataMember.


    Please test removing the ObjectDataSource component and set the report's DataSource directly to the instantiated data object e.g.:
    var data = new GetData(123);
    report.DataSource = data;

    Regards,
    Stef
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
Back to Top