Provides property options to pass or set report parameters default values at run-time using the parameters property. You can set the report parameters while creating the Report Viewer control in a application loaded.
In this tutorial, the
sales-order-dtail.rdl
report is used, and it can be downloaded from here.
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.
The following code example illustrates how to set report parameter in the ReportLoaded
event.
this.ReportViewer.ReportLoaded += (sen, arg) =>
{
List<BoldReports.UI.Xaml.ReportParameter> parameters = new List<BoldReports.UI.Xaml.ReportParameter>();
BoldReports.UI.Xaml.ReportParameter parameter = new BoldReports.UI.Xaml.ReportParameter();
parameter.Name = "SalesOrderNumber";
parameter.Values = new List<string>() { "SO50756" };
parameters.Add(parameter);
this.ReportViewer.SetParameters(parameters);
};
this.ReportViewer.ReportServiceURL = @"https://demos.boldreports.com/services/api/ReportViewer";
this.ReportViewer.ReportPath = "~/Resources/docs/sales-order-detail.rdl";
this.ReportViewer.RefreshReport();
Set the report path ReportPath
and ReportServiceURL
properties of the Report Viewer as in following code snippet.
this.ReportViewer.ReportServiceURL = @"https://demos.boldreports.com/services/api/ReportViewer";
this.ReportViewer.ReportPath = "~/Resources/docs/sales-order-dtail.rdl";
this.ReportViewer.RefreshReport();
To set parameter default value in Web API Controller, use the following code in the OnReportLoaded
method.
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
List<BoldReports.Web.ReportParameter> userParameters = new List<BoldReports.Web.ReportParameter>();
userParameters.Add(new BoldReports.Web.ReportParameter()
{
Name = "SalesOrderNumber",
Values = new List<string>() { "SO50756" }
});
reportOption.ReportModel.Parameters = userParameters;
}
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.UI.Xaml.ReportParameter> parameters = new List<BoldReports.UI.Xaml.ReportParameter>();
if (reportParameters != null)
{
foreach (var parameter in reportParameters)
{
parameters.Add(new BoldReports.UI.Xaml.ReportParameter()
{
Name = parameter.Name,
Values = new List<string>() { "SO50756" }
});
}
}
this.ReportViewer.SetParameters(parameters);
};
this.ReportViewer.ReportServiceURL = @"https://demos.boldreports.com/services/api/ReportViewer";
this.ReportViewer.ReportPath = "~/Resources/docs/sales-order-detail.rdl";
this.ReportViewer.RefreshReport();
The ReportHelper
class provides methods that help you to get the report parameters used in the report. The following helper methods used to get parameter with or without values.
Methods | Description |
---|---|
GetParameters | Returns the parameters that are used in the current report without the processed values. |
GetParametersWithValues | Returns the report parameters with processed data values that are used in the current report. |
You can use the following code sample to get parameter names and set parameter default values.
Set the report path ReportPath
and ReportServiceURL
properties of the Report Viewer as in following code snippet.
this.ReportViewer.ReportServiceURL = @"https://demos.boldreports.com/services/api/ReportViewer";
this.ReportViewer.ReportPath = "~/Resources/docs/sales-order-dtail.rdl";
this.ReportViewer.RefreshReport();
To set parameter default value based on the parameter name in Web API Controller, use the following code in the OnReportLoaded
method.
public class ReportViewerController : ApiController, IReportController
{
Dictionary<string, object> jsonArray = null;
public object PostReportAction(Dictionary<string, object> jsonResult)
{
jsonArray = jsonResult;
return ReportHelper.ProcessReport(jsonResult, this);
}
....
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
var reportParameters = ReportHelper.GetParameters(jsonArray, this);
List<BoldReports.Web.ReportParameter> setParameters = new List<BoldReports.Web.ReportParameter>();
if (reportParameters != null)
{
foreach (var rptParameter in reportParameters)
{
setParameters.Add(new BoldReports.Web.ReportParameter()
{
Name = rptParameter.Name,
Values = new List<string>() { "SO50756" }
});
}
reportOption.ReportModel.Parameters = setParameters;
}
}
}