ActiveReports is a flexible .NET report generator with a complete set of controls and extensive API that allows you to design reports in your Visual Studio projects. This post will demonstrate how to create a banded report in ActiveReports.NET using code-based Section Reports. ActiveReports also has two other powerful and flexible report types. Please look at this page to learn more about our different report types.
Let’s create a simple tabular report of our stock inventory grouped by each product category. We’ll use an existing Visual Studio project, though you can create a new one. We’ll right-click our reports directory and select Add > New Item. Select the ActiveReports 16 Section Report (code-based) in the resulting dialog box and enter a report name.
First thing, let's establish a connection to a JSON endpoint. On the Visual Studio 2022 toolbar, go to Extensions > Report > Data Source. Alternatively, you can click on the Data Source icon in the Detail band of the report:
Go to the JSON tab of the Report Data Source dialog box. Type in your connection string and query in the appropriate fields as follows:
If you need help creating your connection string, click on the Build button next to Connection String. Here, you can easily configure your JSON connection. Similarly, if you need help crafting your query, click on the Build button next to JsonPath, which will launch the JSON Query Designer. Once you are all done, click OK.
You should have all your fields from the dataset in your Report Explorer. Let's right-click on Fields>Calculated to add a custom field to our .NET report.
We'll use this custom field to calculate the value of each product. To do so, we'll set the following properties:
We want to group the data by CategoryID and aggregate the value of each grouping. Right-click the Details band and select Insert > Group Header/Footer. Click on the Group Header and set the DataField property to CategoryID to group the report on this field. Also, set the BackColor property to WhiteSmoke. Finally, set the KeepTogether property to True. This ensures that the grouping will not be broken across multiple pages whenever possible.
At the top of the Group Header, add two labels ("Category:" and "Category Value:") vertically aligned. Next to each, drag and drop CategoryId and Value from the Fields section of your Report Explorer. The Value textbox will display the total value of the category. Therefore, we need to adjust some properties for this textbox:
At the bottom of the Group Header, add 4 Labels:
In the Details band, drag and drop ProductName, UnitsInStock, and UnitPrice from the Bound Fields and Value from the Calculated fields. Adjust the size and position of the text boxes to align with their respective labels in the Group Header. Adjust the height of the Group Header, Detail, and Group Footer. At this point, your report layout will look like this:
Previewing, the sizing looks right now. We also see that the groups are kept together as much as possible.
Download this sample as an RPX file from the link below inventory.rpx
Learn more about ActiveReports.NET features by visiting our Online Demos.