Set report source dynamically in trdp file.

2 posts, 0 answers
  1. Deepak
    Deepak avatar
    2 posts
    Member since:
    Jul 2019

    Posted 18 Jul Link to this post

    Can we set report data  source dynamically in .trdp file, without using the wizard?
  2. Silviya
    Admin
    Silviya avatar
    414 posts

    Posted 23 Jul Link to this post

    Hello Deepak,

    I noticed that you've opened a support ticket on the same topic. I'll post my answer here as well:

    'If I understood the requirement correctly, you need to set the data source of the report created with our Standalone Report Designer, from code-behind. Also, I assume that the datasource will be either coming from a web service or an inline JSON file.

    When working with TRDP reports you can use the ReportPackager class to unpackage the report. For more information, please check the Report Unpackaging help article. The ReportPackager.Unpackage Method will return a Telerik.Reporting.Report object which you can use and modify.

    When report is served by Reporting REST service to HTML5 report viewer, all run-time modifications to report need to happen in custom report resolver used by the service. So, the steps would be the following:

    1. Unpackage the TRDP report to apply modifications:
    var reportPackager = new ReportPackager();
    using (var sourceStream = System.IO.File.OpenRead("Report1.trdp"))
    {
        var report = (Report)reportPackager.UnpackageDocument(sourceStream);
    }

    2. After you have the report object available, you can modify its definition based on the Reporting API Reference:
    //create the data source
    report.DataSource = //assign new data source here
    var irs = new InstanceReportSource();
    irs.ReportDocument = report;
    this.reportViewer1.ReportSource = irs;

     Note that the instantiated report will be passed to the reporting engine wrapped in an InstanceReportSource. It is important that resolver's Resolve() method returns the same report source for the same value of the string passed with reportSource.report option of the viewer.
    '


    Best Regards,
    Silviya
    Progress Telerik
    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
Back to Top