How to Drill Through Reports in a C# .NET Application
This blog will show how to drill through from one report to another using ActiveReports. This tutorial discusses how to display a child report when a user clicks on text or an object in the main report.
This blog is accompanied by a video. Both the video and the blog will go through the same steps to achieve the same results. If you'd like to follow the video instead or use both together:
We’ll continue using the report we generated in our Getting Started - How to Create a .NET Report.
Ready to Get Started? Download ActiveReports.NET Today!
As a reminder, this is an inventory report using a table grouped into product categories. It shows each product’s name, color, price, and size.
We also have a second report showing a list of recent orders, including the customer’s name, the quantity they ordered, the price per quantity, any discount we’re giving them, and a total for that line item.
So, the goal here will be to drill through the first report, the Inventory Report, to see the Recent Orders report for a particular product category. If we click on the image of a product category in the Inventory Report, the Recent Orders report for that product category should display.
First, we’ll create some parameters to hold the ProductID and ProductName of the products we click on in our Inventory Report.
1. Open the Recent Orders report in the ActiveReports Designer.
- This time, we will use the ActiveReports Visual Studio Integrated Designer as our example. Still, you can also use the ActiveReports Desktop Designer or the ActiveReports Web Designer to do the same thing with similar steps.
2. Right-click on parameters in the Report Explorer and choose Add Parameter.
3. Set the Name to ProductID.
4. Check the checkbox next to Hidden.
- This will hide the parameter from users so they cannot interact with it directly but allows us to continue using it in the background.
5. Click the green + button at the top of the parameters dialog to add another parameter.
6. Name this one ProductName and change it to Hidden as well.
7. Click OK.
Next, we’ll change the title in our Recent Orders report to include the ProductName stored in our parameter and filter the data in the report by the ProductID.
1. Remove the existing “Recent Orders” text from the title checkbox
2. Replace that old text with an expression:
- =”Recent Orders for ““&[@ProductName]&””
3. Right-click on the Orders data set and choose Edit
4. In the Parameters tab of the DataSet dialog, add a new parameter
- Set the Name to QueryParameter
- Set the value to =Parameters!ProductID.Value
5. Open the Query tab of the DataSet dialog
6. At the end of the query, add the following:
- where SalesLT.SalesOrderDetail.ProductID = @QueryParameter
7. Click OK
Now, we can jump back into the Inventory Report, where we’ll add an Action event on the image to allow users to click on it to open the Recent Orders report for the pictured product.
1. Open the Inventory Report in the ActiveReports Designer
2. Select the image control embedded in the first cell of the table and open the property dialog box
3. Open the Navigation tab in the Image dialog
4. Select Jump to report and set the dropdown to our Recent_Orders report
5. In the table below the dropdown, we’ll need to add two parameters: the parameters we’re passing into our Recent Orders report. The names of these parameters should match the ones in our Recent Orders report.
- Name: ProductID, Value: =Fields!ProductID.Value, Omit: false
- Name: ProductName, Value: =Fields!Name.Value, Omit: false
And that’s it! Everything should be working the way we planned now. If you click on a product image in the Inventory Report, it should drill through to the Recent Orders for that product.
Ready to Get Started? Download ActiveReports.NET Today!