I'm using a HTML5 Web Forms Report Viewer
Here is my code:
var reportPackager = new ReportPackager();
var reportInstance = new Report();
using (var sourceStream = System.IO.File.OpenRead("PathToTRDPFile"))
{
reportInstance = (Report)reportPackager.UnpackageDocument(sourceStream);
}
var table3 = reportInstance.Items.Find("table3", true)[0] as Telerik.Reporting.Table;
table3.DataSource = CreateDataTable(); //A function that returns a datatable
var instanceReportSource = new InstanceReportSource { ReportDocument = reportInstance };
this.reportViewer1.ReportSource = instanceReportSource;
The error that I got:
Error CS0029 Cannot implicitly convert type 'Telerik.Reporting.InstanceReportSource' to 'Telerik.ReportViewer.Html5.WebForms.ReportSource'
Any idea on how to resolve this?
Hi Adrian,
I suspect that you have placed this code in the code behind of the page of the viewer. You need to create a Custom Report Source Resolver and the logic for assigning the datasource in the Resolve method:
class CustomReportSourceResolver : IReportSourceResolver { public Telerik.Reporting.ReportSource Resolve(string reportId, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues) { var reportPackager = new ReportPackager(); var reportInstance = new Report(); using (var sourceStream = System.IO.File.OpenRead("PathToTRDPFile")) { reportInstance = (Report)reportPackager.UnpackageDocument(sourceStream); } var table3 = reportInstance.Items.Find("table3", true)[0] as Telerik.Reporting.Table; table3.DataSource = CreateDataTable(); //A function that returns a datatable var instanceReportSource = new InstanceReportSource { ReportDocument = reportInstance }; return instanceReportSource; } }
Then in the ReportsController, set the ReportSourceResolver = new CustomReportSourceResolver().
Please, test this approach and let me know if everything works on your end.