In a Section report, you can use the Parameters collection to pass values directly into a control, or you can also use it to display a subset of data in a particular instance of the report.
There are several ways to set up parameters in a report:
Section report allows you to add parameters to a report's Parameters collection via the SQL query. You can add build queries with parameters using following easy steps:
Query |
Copy Code
|
---|---|
SELECT * FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID= [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID WHERE Products.SupplierID = <%SupplierID|Enter Supplier ID|7|||%> AND OrderDate >= #<%OrderDate|Order date from|11/1/1994|D|true|yyyy/MM/dd%># AND Discontinued = <%Discontinued|Is this checked?|true|B||%> |
You can also add SQL query using the Visual Query Designer. To do so, click on the Query Designer button, select the Design option, and select the desired fields to create the query. To preview the query, click on the SQL option and then click Save.
The SQL query above causes ActiveReports to display the following dialog to the user at runtime. The user can accept these or input other values to select report data.
The values below are used while creating the parameter syntax. The values in the parameter syntax are separated by the pipe character (|).
For creating a parameter syntax, the first value (Name) is required. However, if the DefaultValue is not specified, the fields are not populated at the design time. In the syntax, you can provide only the Name value (without pipe character), or you can provide some values along with the Name value and use pipes without space for the missing values. For example, <%ProductID||||False|%>.
D (date): Provides a drop-down calendar picker from which the user can select a date. Depending on your data source, you may need to put number signs around the parameter syntax.
For example, #<%MyDateParameter%>#
The steps to add a parameter from Report Explorer are as follows:
You can add, edit, and delete parameters at runtime. The following code demonstrates how to add a parameter and display its value in a Textbox control.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste at beginning of code view. |
Copy Code
|
---|---|
Imports GrapeCity.ActiveReports.SectionReportModel |
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
Dim myParam1 As New Parameter() |
To write the code in C#
C# code. Paste at beginning of code view. |
Copy Code
|
---|---|
using GrapeCity.ActiveReports.SectionReportModel; |
C# code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
Parameter myParam1 = new Parameter(); |
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the FetchData event. |
Copy Code
|
---|---|
'Set textbox text equal to the value of the parameter. Me.txtParam1.Text = Me.Parameters("myParam1").Value |
To write the code in C#
C# code. Paste INSIDE the FetchData event. |
Copy Code
|
---|---|
//Set textbox text equal to the value of the parameter. this.txtParam1.Text = this.Parameters["myParam1"].Value; |
In order to prompt the user for parameter values, all of the following must be in place:
When there are parameters in the collection and the ShowParameterUI property is set to True, the user prompt automatically displays when the report is run. When the user enters the requested values and clicks the OK button, the report gets displayed using the specified values.
Values of a parameter added through the Report Explorer can be applied to a parameter in the SQL query by specifying the param: prefix for a parameter in the SQL query. This prefix relates the current parameter to the one in the Report Explorer.
For e.g., SELECT * FROM CUSTOMERS WHERE CustomerName = '<%param:Parameter1%>'. In this case, the parameter with the param: prefix in the SQL query is updated with values of the corresponding parameter in the Report Explorer.
Note: Within the same report, you can prompt users for some parameters and not for others by setting the PromptUser property to True for some and False for others. However, if the report object's ShowParameterUI property is set to False, the user prompt does not display any parameters, regardless of its PromptUser setting.