Skip to main content Skip to footer

How to Add Parameters to Your C# .NET Report Application

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. 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.

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.

C# Report Parameters

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

select DISTINCT color
from SalesLT.Product
where SalesLT.Product.Color is not null

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:”

C# Report Parameters

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

C# Report Parameters

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

C# Report Parameters

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)

select *
from SalesLT.Product
where (SalesLT.Product.Color=@QueryParam AND
(SalesLT.Product.Thumbnailphotofilename not in (select
SalesLT.Product.thumbnailphotofilename from SalesLT.Product where
SalesLT.Product.thumbnailphotofilename = 'no_image_available_small.gif')))

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.

C# Report Parameters

And the resulting report preview will be filtered only to show products of that color.

C# Report Parameters


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.



comments powered by Disqus