Changing a report's data sources

1 Answer 768 Views
DataSource Object General Discussions Programming
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
Neil N asked on 11 Jun 2021, 04:50 PM

Goal: Change a trdx's web services data sources from using web service requests to using inline data strings and then render a PDF.

The trdx was created using the Invoice Report Wizard and has two data sources (one for header and one for detail). Both actually call the same web service method but use different data selectors ($.result and $.result.MemberReceiptDetails). I need to replace these calls with inline json strings (again, they'll be identical) and remove the parameters.  I see the Report class has a DataSource property but how does this relate to multiple datasources?.

 

            XmlReportSource reportSource = new XmlReportSource();

            Report report = GetReportFromResources("Member.DuesReceipt.trdx");

            //Change data sources here

            StringBuilder builder = new StringBuilder();
            using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(builder))
            {
                Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
                    new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

                xmlSerializer.Serialize(xmlWriter, report);
            }

            reportSource.Xml = builder.ToString();

            var reportProcessor = new ReportProcessor();
            RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, null);

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 15 Jun 2021, 12:22 PM

Hi Neil,

The Report Class represents the base class for any report in the Telerik Reporting. Each Report implements the IDataItem Interface and as such, each report has a DataSource property to which you can assign a single data source. This DataSource property is just like in the Table, List, Crosstab, etc. report items and does not actually hold the data sources defined in the report. In fact, currently, the report does not expose its DataSources list but we have planned to make the list public in the R3 2021 release - Make Report.DataSources property public

So if you want to edit the data source of a data item, such as a table's DataSource, you need to find that report item in the Items collection of the report and then assign it the new data source. For example, if you had a table with the Name table1, you can find it and change its DataSource the following way:

Table item = (Table)report.Items.Find("table1", true).FirstOrDefault();
 item.DataSource = yourData

Please let me know if you have any other questions or need further help. Thank you for using Telerik Reporting!

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
DataSource Object General Discussions Programming
Asked by
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Dimitar
Telerik team
Share this question
or