How to bind JSON data to subreport(s) at runtime?

Posted by: kyle.chamberlin on 16 February 2022, 5:51 pm EST

  • Posted 16 February 2022, 5:51 pm EST

    I have been following this blog post (https://www.grapecity.com/blogs/how-to-programmatically-bind-data-in-rdl-page-report-using-net) in order to dynamically render ActiveReports 16 RDLs in a .NET 5 Razor Page MVC environment. The LocateDataSource event does what I need; I can hit my API when the page is rendered and supply the results as JSON. The full code for my RdlxViewer page can be found here - https://pastebin.com/cJNf9GmX

    This works for the main report. However, I have not been able to find any documentation or examples describing how to do this for any subreports. There are lots of older threads that talk about how to do this for SQL-like data sources, but I haven’t been able to find anything for JSON, or using LocateDataSource. Is this something I would have to set in the script of the parent RDL somehow?

  • Posted 28 February 2022, 3:09 am EST

    Hello,

    We apologize for the delay in response, we are investigating the above issue and are working on a solution using CustomResourceLocator. We would provide an update on the same at the earliest.

    Regards

    Dushyant Sharma

  • Posted 2 March 2022, 6:11 pm EST

    No problem, thank you very much for the update. I look forward to more information in the future.

  • Posted 3 March 2022, 11:02 pm EST

    Hello,

    Please refer to the following points for the resolution of the above query:

    • Instead of using CustomResourceLocator, we can use LocateDataSource event to set the dataSource at runtime for both the MainReport and SubReport.
    • We will use the “Object Provider” as the DataProvider and should set the required fields within the dataset accordingly.
    • Within the above-described event, we can use the args.Report.Name property to get the name of the report (Parent report or SubReport) for which the given event is called, proceeding which we can use the args. Data property to set the dataSource.

    Please refer to the sample implementing the same below.

    AR_RuntimeDataSource.zip

    Regards

    Dushyant Sharma

  • Posted 9 March 2022, 8:45 am EST

    Thank you very much for the solution. This works in a simplified form, but our use case involves embedding the subreport into another table with one of the row values to be used as a parameter, like so - https://imgur.com/WJNIXFr.

    Through my debugger, I can see that LocateDataSource is being called multiple times for each instance of the subreport, which is good. Is there any way to get the values of the parent table row currently being processed at that point to be used as a filter?

  • Posted 10 March 2022, 4:32 pm EST

    Hello,

    We don’t have to explicitly get and pass the values from the MainReport’s table to filter the data for the subReport. We can use the below approach to pass the values within the subReport.

    • To pass the values from the table of the MainReport to the subReport control, we can define the parameter properties of the SubReport control (in the MainReport) and define the subReport’s report parameter within it accordingly.

    • To get the filtered data within the subReport, we can use the Dataset filter, to filter the data within the subreport.

    Hope it helps. Please let me know in case you have any other queries or if I missed something.

    Please refer to the attached sample implementing the same below.

    AR_RuntimeDataSource_updated.zip

    Regards

    Dushyant Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels