Report parameters
To set report parameters in the Bold Reports® UWP 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 your application.
This tutorial uses the
sales-order-dtail.rdlreport. Download the sales-order-detail report.
How do I set a report parameter?
To set a report parameter in the UWP Report Viewer, assign the parameter name and default value, then call the SetParameters method in the ReportLoaded event.
-
Set the default value data to the
Valuesproperty and name of the report parameter to theNameproperty.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
ReportLoadedevent.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();
How do I set parameters in the Web API controller?
To set a report parameter default value in the Web API controller, set the ReportPath and ReportServiceURL properties of the UWP Report Viewer and use the OnReportLoaded method.
-
Set the report path
ReportPathandReportServiceURLproperties 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
OnReportLoadedmethod.[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; }
How do I get the report parameters?
To get the report parameters in the UWP Report Viewer, call the GetParameters method. The following table describes the method.
| 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();How do I get the report parameters in the Web API controller?
To get the report parameters in the Web API controller, use the ReportHelper class methods. The following helper methods get parameters 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
ReportPathandReportServiceURLproperties 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
OnReportLoadedmethod.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; } } }