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

Programmatically initialization of report's DataSource property by ObjectDataSource instances

2 Answers 1090 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nikita
Top achievements
Rank 1
Nikita asked on 03 Apr 2020, 12:35 PM

Hi,

 

I have Telerik report designed in Telerik Report Designer.

It contains two object data sources.

I programmatically load trdp file and initialize DataSource property of Report object by two Object Data Source Instances.

In generated report I see strange behavior: table is bound to first data source is duplicated.
Questions:
1.Why report object contains DataSource property = null?
2.in the spec. it's written, that DataSource should be initialized by object derived from IEnumerable interface as well, but when report is rendered, it doesn't take all instances of passes Object Data Sources, but just duplicate first one.

Source code:

var reportPath = HttpContext.Current.Server.MapPath("~/Reports") + "/InvoiceAppendix2.trdp";
 
using (var sourceStream = System.IO.File.OpenRead(reportPath))
{
    var report = (Report)reportPackager.UnpackageDocument(sourceStream);
 
    //prepare report parameters
    report.ReportParameters["SalesOrderId"].Value = salesOrderId;
 
    //init data source
    var dataSource1 = new ObjectDataSource();
    dataSource1.DataSource = typeof(SalesOrderBDS);
    dataSource1.DataMember = "GetSalesOrders";
    dataSource1.Name = "SalesOrderInfoBO";
    dataSource1.Parameters.Add(new ObjectDataSourceParameter("salesOrderId", typeof(int), salesOrderId));
 
    var dataSource2 = new ObjectDataSource();
    dataSource2.DataSource = typeof(JobJacketBDS);
    dataSource2.DataMember = "GetJobJackets";
    dataSource1.Name = "JobJacketInfoBO";
    dataSource2.Parameters.Add(new ObjectDataSourceParameter("salesOrderId", typeof(int), salesOrderId));
 
    report.DataSource = new ObjectDataSource[] { dataSource1, dataSource2 };
 
    var reportProcessor = new ReportProcessor();
    var instanceReportSource = new InstanceReportSource();
    instanceReportSource.ReportDocument = report;
 
    var result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
 
    var stream = new MemoryStream(result.DocumentBytes);
    return new Classes.FileResult(stream, "application/pdf", $"InvoiceAppendix_{salesOrderId}.pdf", true);
}

2 Answers, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 08 Apr 2020, 08:53 AM

Hello Nikita,

Data items (Report, Table, CrossTab, Graph items, .etc) do not support binding to multiple DataSource components. If the data item's DataSource property references an array of business objects these objects must contain public properties that later can be used in report expressions. The Reporting engine does not have a mechanism to invoke the DataMember and DataSource properties of the collection of ObjectDataSources.

You can display the data using multiple data items each bound to its own data source.

 

Regards,
Katia
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Nikita
Top achievements
Rank 1
answered on 08 Apr 2020, 08:57 AM

Hi Katia,

Thank you for the response.

I've found, that only one instance of an object can be assigned to DataSource property, So several methods on the instance could be used as data sources for items in report designer.

Tags
General Discussions
Asked by
Nikita
Top achievements
Rank 1
Answers by
Katia
Telerik team
Nikita
Top achievements
Rank 1
Share this question
or