Report parameters

To set report parameters in the Bold Reports® WPF Report Viewer, pass the default values at run time using the parameters property. You can set the report parameters while creating the Report Viewer control in a loaded application.

In this tutorial, the sales-order-dtail.rdl report is used, and it can be downloaded from the sales order detail report download.

How do I set a report parameter?

To set a report parameter in the Bold Reports® WPF Report Viewer, pass its name and default values in the ReportLoaded event, as in the following steps:

  1. Set the default value data to the Values property and name of the report parameter to the Name property.

    The parameter name is case sensitive, it should be same as available in the report definition.

  2. The following code example illustrates how to set a report parameter in your application code.

    this.reportViewer.ReportLoaded += (sen, arg) =>
    {
        List<BoldReports.Windows.ReportParameter> parameters = new List<BoldReports.Windows.ReportParameter>();
        BoldReports.Windows.ReportParameter parameter = new BoldReports.Windows.ReportParameter();
        parameter.Name = "SalesOrderNumber";
        parameter.Values = new List<string>() { "SO50756" };
        parameters.Add(parameter);
        this.reportViewer.SetParameters(parameters);
    };
    this.reportViewer.ReportPath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\sales-order-detail.rdl");
    this.reportViewer.RefreshReport();

How do I get the report parameters?

To get the report parameters used in a report, call the GetParameters method of the Report Viewer.

Methods Description
GetParameters Returns the parameters that are used in the current report without the processed values.

You can use the following code sample to get parameter names and set parameter default values.

this.reportViewer.ReportLoaded += (sen, arg) =>
{
    var reportParameters = this.reportViewer.GetParameters();
    List<BoldReports.Windows.ReportParameter> parameters = new List<BoldReports.Windows.ReportParameter>();

    if (reportParameters != null)
    {
        foreach (var parameter in reportParameters)
        {
            parameters.Add(new BoldReports.Windows.ReportParameter()
            {
                Name = parameter.Name,
                Values = new List<string>() { "SO50756" }
            });
        }
    }

    this.reportViewer.SetParameters(parameters);
};
this.reportViewer.ReportPath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\sales-order-detail.rdl");
this.reportViewer.RefreshReport();