Using JSON data requires some setup that is different from other types of data. This walkthrough illustrates how to set up a subreport bound to the JSON data source in the parent report.
When you complete this walkthrough you get a layout that looks similar to the following at design time and at run time.
JSON File URL |
Copy Code
|
---|---|
https://demodata.mescius.io/northwind/odata/v1/Categories?$expand=Products
|
Connection String |
Copy Code
|
---|---|
jsondoc=https://demodata.mescius.io/northwind/odata/v1/Categories?$expand=Products
|
Query |
Copy Code
|
---|---|
$.value[*] |
Property Name | Property Value |
---|---|
TextBox1 | |
DataField | ProductName |
Name | txtProductName |
TextBox2 | |
DataField | UnitPrice |
Name | txtUnitPrice |
OutputFormat | $#,##0.00 (or select Currency in the dialog) |
VB Code:
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. |
Copy Code
|
---|---|
Dim rpt As rptSub |
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
rpt = New rptSub()
|
C# Code:
The following example shows what the code for the method looks like.
C# code. Paste JUST ABOVE the ReportStart event. |
Copy Code
|
---|---|
private rptSub rpt;
|
C# code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
rpt = new rptSub();
|
To add code to pass a subset of the parent report's data to the subreport
The following example shows what the code for the method looks like.
Visual Basic.NET code. Paste INSIDE the Format event. Copy Code Dim jsonDS As New GrapeCity.ActiveReports.Data.JsonDataSource jsonDS.JsonData = (CType(Me.DataSource, GrapeCity.ActiveReports.Data.JsonDataSource)).Field("Products").ToString() jsonDS.JsonPath = "$.[*]" rpt.DataSource = jsonDS SubReport1.Report = rpt
C# code. Paste INSIDE the Format event. Copy Code GrapeCity.ActiveReports.Data.JsonDataSource jsonDS = new GrapeCity.ActiveReports.Data.JsonDataSource(); jsonDS.JsonData = ((GrapeCity.ActiveReports.Data.JsonDataSource)this.DataSource).Field("Products").ToString(); jsonDS.JsonPath = "$.[*]"; rpt.DataSource = jsonDS; subReport1.Report = rpt;
Click the preview tab to view the report at design time.