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

Runtime ObjectDataSource is overwritten when refreshing report

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 05 Sep 2016, 12:00 PM

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

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 07 Sep 2016, 04:48 PM
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
Tags
General Discussions
Asked by
Phil
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or