How to Add Parameters to Your C# .NET Report Application
Quick Start Guide | |
---|---|
What You Will Need |
ActiveReports.NET License (Free trial or full license) |
Controls Referenced | |
Tutorial Concept | Learn how to add parameters to your C# .NET application to enhance flexibility and user input handling. This tutorial covers defining, passing, and using parameters effectively to improve application functionality. |
In ActiveReports.NET, parameters enable you and/or your end users to control report data, connect related reports together, and vary report presentation. Report parameters can be used to solve tasks such as filtering, conditional formatting, data binding, creating dynamic report layouts, and much more.
This blog is accompanied by a video. Both the video and the blog will go through the same steps to achieve the same results. We will cover how to:
If you'd like to follow the video instead or use both together:
In this guide, we’ll show how easy it is to work with parameters in ActiveReports. We’ll continue using the report that we generated in our Getting Started - How to Create a .NET Report guide.
Ready to Get Started? Download ActiveReports.NET Today!
As a reminder, this is an inventory report using a table that is grouped by product categories. It shows each product’s name, color, price, and size.
We want to filter this report based on color. Therefore, we'll need to create a parameter to indicate that the user needs to select a color, pass that selection to the report, and filter the data based on that parameter.
Section 1: Add a dataset for the parameter values
First, we'll create another dataset specifically for the parameter values.
1. Right-click the MyDS data source node and select “Add Data Set.”
2. Set the name to “ParamDataSet”
3. On the Query tab, I want to query a list of distinct colors from my Products table
4. Click OK to close the dialog box.
Section 2: How to add a parameter
Now, we need to create a parameter input field in the report so the user is prompted to make a selection.
1. Right-click the “parameters” node in the Report Explorer and select “Add Parameter.”
2. On the resulting dialog box’s General tab, we’ll rename the parameter and enter a text that directs the user to make a selection.
- Name: “ReportParam”
- Text: “Select ‘color’ of your choice:”
3. On the Available Values tab, we’ll select “From Query” since we created a Dataset for this parameter. We’ll select the Dataset we created earlier, “ParamDataSet” from the Dataset drop-down.
4. The Value and Label fields will only have one choice since that’s the only field we have selected in our query.
- Select “color” for both
5. Click OK to close the dialog box.
Section 3: Pass the parameter
Next, we need to edit the Products dataset and pass the parameter to the Products query.
1. Right-click the “Products” data set and choose “Edit.”
2. In the Products Data Set dialog box, go to the “Parameters” tab
3. Add a Parameter
4. Rename it to QueryParam
5. Pass the value from the report parameter created in Section 2 using an expression
- =Parameters!ReportParam_color.Value
6. On the Query tab, we’ll add the query parameter (which we just created) to the where clause and filter the query based on the value of the parameter selected. (Line 3 of the snippet below)
Now you should be good to go! If we run the project, we should now have a dropdown box where the user can select a color.
And the resulting report preview will be filtered only to show products of that color.
Adding parameters to your C# .NET application enhances its flexibility, making it more dynamic and user-friendly. By implementing the techniques covered in this guide, you can efficiently handle user input, customize application behavior, and improve overall functionality. Start integrating parameters into your projects today to unlock greater control and adaptability in your applications.
Additional tutorials are available on our ActiveReports blog page. Develop and deploy custom enterprise .NET reports with these award-winning complete reporting solutions by downloading a free 30-day trial.