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

Objectdatasource called multiple times

1 Answer 309 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bernard
Top achievements
Rank 1
Bernard asked on 23 Mar 2015, 04:55 PM
I am currently designing a reference implementation for the incorporation of Telerik Reporting into both our Desktop and Web clients.

The design goals for us are:
Provide design time support for both the Visual Studio Designer and the StandAlone Designer, including working sample data.
Allow the runtime application to retrieve the data async from our Rest based backend.
Only use Business Objects types for the design time experience.


So i started out creating a sample Datasource that has a constructor without parameters and constructor with parameters. The thought process was that the default constructor would pump out static data to enable design time support and the version with the constructor would use the version with parameters which i could inject during runtime to support async loading before the datasource is created.

The first report I created is a simple table report listing firstname and lastname. Design time support is working as expected within visual studio so the next step was to add a reportviewer to a wpf application and start injecting real data.

At first glance everything seemed to be working fine the correct methods get called by report and report is rendering ok, what is not ok is that the reportviewer actually re-initiliazes the datasource therefore going back to the original version with static data after i've bound it to an actual reportviewer. Behauviour is that i get one call to the correct datasource, and after that one the object is recreated and goes to static data.

I assume this is due an error on my part. Please look at the code where i initialize the reportviewer.

List<TestPerson> TestPersons = new List<TestPerson>();
TestPersons.Add(new TestPerson
{
FirstName = "Mikey",
LastName = "Mouse"
});


var typeReportSource = new Telerik.Reporting.TypeReportSource();
typeReportSource.TypeName = "ReportLibrary.Report1, Reportlibrary";
Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
objectDataSource.DataSource = new SampleDatasource.tempdatasource(TestPersons);
objectDataSource.DataMember = "GetData"; // Specifying the name of the data object method

Telerik.Reporting.Report report = new ReportLibrary1.Report1();
report.DataSource = objectDataSource;
Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
ReportViewer.ReportSource = reportSource;



ReportViewer.RefreshReport();
ReportViewer.RefreshData();


Or look at the complete attached solution.

1 Answer, 1 is accepted

Sort by
0
Bernard
Top achievements
Rank 1
answered on 26 Mar 2015, 11:03 AM
After working with Stef (Telerik Support) who was good enough to help correct my sample project I am happy to report everything is now working is i orginally intended it.

The caveat was that both the report itself and the datatable within the report need to be assigned a correct and working objectdatasource for everything to work. 

 
01.objectDataSource = new Telerik.Reporting.ObjectDataSource();
02. objectDataSource.DataSource = new tempdatasource(TestPersons);
03. objectDataSource.DataMember = "GetData"; // Specifying the name of the data object method
04. objectDataSource.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter("production", typeof(bool), "=Parameters.production.Value"));
05. 
06. Telerik.Reporting.Report report = new ReportLibrary1.Report1();
07. (report.Items.Find("table1", true)[0] as Telerik.Reporting.Table).DataSource = objectDataSource;
08. 
09. Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
10. reportSource.ReportDocument = report;
11. //the report source Parameters collection is mapped to the report's ReportParameters collection by key
12. reportSource.Parameters.Add("production", true);
13. ReportViewer1.ReportSource = reportSource
 

Tags
General Discussions
Asked by
Bernard
Top achievements
Rank 1
Answers by
Bernard
Top achievements
Rank 1
Share this question
or