HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Sunday, July 22, 2012

How to: Create a Report with Parameters

This tutorial describes the steps to create a parameterized report at Visual Studio design time. To simplify the example, we'll pass a single integer parameter, and request it each time the report is being previewed. However, you can specify as many parameters as required, and of any type (e.g. date-time, boolean, string, double, and so on). For general information, refer to Using Report Parameters.

To create a report with a parameter, do the following.

Create a Data-Aware Report

1.      Start MS Visual Studio (2008 or 2010), and create a new application under any of the supported platforms, or open an existing one.

2.      Add a new blank report to it.

3.      Bind the report to the "Products" table of the sample Northwind database (nwind.mdb file, which is shipped with the XtraReports installation).

4.      Drag the CategoryID and ProductName fields from the Field List window and drop them onto the report's Detail band.

Add a Parameter

5.      To add a parameter to the report, in the Field List, right-click the Parameters section and choose Add Parameter.

6.      In the invoked window, set the name of the created parameter and choose its type.

7.      Then, click your report's smart tag, and in its actions list, click the ellipsis button for the XtraReportBase.FilterString property.

In the invoked FilterString Editor, construct an expression, where the CategoryID data field is compared with the Category parameter. To access the parameter, click the icon on the right, until it turns into a question mark.

Now, this parameter will be requested each time the report is being previewed. If this is not required, you can specify a static value for the parameter's Parameter.Value property, and disable its Parameter.Visible property. This will silently pass the parameter's value to your report.

Get the Result

The parameterized report is now ready. Switch to the Preview tab, and then in the Parameters panel, enter a value for the parameter, and click Submit.

 

No comments:

Post a Comment