Databases Reference
In-Depth Information
Retrieving Report Parameters
The next area of programmatic rendering consists of retrieving a list of parameters for your report. This
bit of code can be used in a number of scenarios. The parameter interface that is provided by Reporting
Services works well for simple parameters. However, it does not handle many things, like multiselect
parameters or more advanced interfaces such as calendar controls. Being able to return a list of parame-
ters allows you to create your own dynamic interface.
In the following example, we will create a simple list of parameters. For each parameter, we will dynam-
ically add a label control and text box to your form. This example will also include the GetParameters
click event to run your code. First thing you need to do is identify the report that is selected in your
report drop-down list.
C#
ReportItem reportItem = (ReportItem)cboReports.SelectedItem;
VB
Dim reportItem As ReportItem = CType(cboReports.SelectedItem, ReportItem)
This creates a new ReportItem variable using the selected item of your combo box. The ReportItem
class created in the previous section contains a Name and Path property. You can use this Path property
to retrieve your list of parameters.
To return your list of parameters, call the GetReportParameters method or the ReportingService
object. This method has two functions. It returns a list of parameters and can validate parameters against
the available values defined when creating the report. Let's take a look at the arguments of the
GetReportParameters method:
Report: This is the path to the report you want to retrieve.
HistoryID: The ID used to identify any historical snapshots of your report.
ForRendering: This Boolean argument can be used to retrieve the parameters that were set when
the report was executed. For example, you might create a snapshot of your report or receive it in
an e-mail subscription. In both cases, the report is executed before the user views it. By setting the
ForRendering property to true, you can retrieve these values and use them in your own custom
interface.
ParameterValues: The ParameterValues argument can be used to validate the values
assigned to a parameter. This can be useful in guaranteeing that the parameter values you pass
to your report match the parameter values accepted by the report.
Credentials: The database credentials to use when validating your query-based parameters.
Since you are not working with historical reports or validating values, a number of the properties will
not be set. The following code can be used for calling the GetReportParameters method.
C#
ReportParameter[] parameters;
parameters = _rs.GetReportParameters(reportItem.Path, null, false, null, null);
Search WWH ::




Custom Search