Users can control how data is used in a report by taking advantage of the Report Parameters feature in Telerik Reporting. You can add parameters to your reports at design time through an editor, at runtime through a user interface in the Report Viewer, programmatically, or via a SubReport parameter collection. In this post I’ll show you how to set up a report that allows users to enter parameter values through the UI of the Report Viewer. This functionality provides users with the means to filter their reports quickly so that only the most relevant data is displayed.
Setup the Report
To get started, create a new class library project in Visual Studio, name it ReportLibrary, and add to it a Telerik Report. When you are greeted with the Telerik Report Wizard, click Next until you are on the Choose Data Source page. Select Create new Data Source and click Next.
On the following page, select Database as your data source type and click Next.
SELECT [t1].[CompanyName], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShipCountry], (
SELECT SUM([t3].[value])
FROM (
SELECT (CONVERT(Decimal(29,4),[t2].[Quantity])) * [t2].[UnitPrice] * (CONVERT(Decimal(29,4),1 - [t2].[Discount])) AS [value], [t2].[OrderID]
FROM [Order Details] AS [t2]
) AS [t3]
WHERE [t3].[OrderID] = [t0].[OrderID]
) AS [OrderTotal]
FROM [Orders] AS [t0]
LEFT OUTER JOIN [Customers] AS [t1] ON [t1].[CustomerID] = [t0].[CustomerID]
I’m no T-SQL guru, so I definitely did not come up with this complicated T-SQL query all on my own. However, I am pretty good at LINQ, so I used LINQPad to write a query against the Northwind database. A nice feature of LINQPad is that it converts your query into T-SQL for you, making my job much easier. Thank goodness for developer tools. But I digress…
Enter a DataSet name of NorthwindOrdersDataSet and click Next.
Add Report Parameters
To add report parameters to your report, simply click on the ReportParameters property in the report properties window.
Create a Filter
Finally, the only thing left to do is to add a filter so that the Orders data displayed within the report falls within the values of the StartDate and EndDate report parameters. Click on the Filters property in the report properties window, which will bring up the Edit Filters dialog. Click New and add the following two new filters:
Wrap Up
Specifying report parameters in the report viewer is just one of the ways to pass values to your reports. As you’ve seen in this demo, report parameters are a very powerful feature as they allow you a greater level of control over the data that is displayed in your report.
If you are interested in the source code used in this demo, you may download it below.
Atanas Keranov was a Software Engineer in the Telerik Reporting division.