Search results

Report Parameters

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 script or in the Web API Controller.

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

Set parameters in Web API Controller

To set parameter default value in Web API Controller, use the following code in the OnReportLoaded method.

public void OnReportLoaded(ReportViewerOptions reportOption)
{
    List<Syncfusion.Reporting.Web.ReportParameter> userParameters = new List<Syncfusion.Reporting.Web.ReportParameter>();
    userParameters.Add(new Syncfusion.Reporting.Web.ReportParameter()
    {
        Name = "SalesOrderNumber",
        Values = new List<string>() { "SO50756" }
    });
    reportOption.ReportModel.Parameters = userParameters;
}

Get report parameter

The ReportHelper class provides methods 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 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.

    public class ReportViewerController : ApiController, IReportController
    {
        Dictionary<string, object> jsonArray = null;
        private IMemoryCache _cache;
        private IHostingEnvironment _hostingEnvironment;

        public ReportViewerController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)
        {
            _cache = memoryCache;
            _hostingEnvironment = hostingEnvironment;
        }

        public object PostReportAction(Dictionary<string, object> jsonResult)
        {
            jsonArray = jsonResult;
            return ReportHelper.ProcessReport(jsonResult, this);
        }

        ....
        public void OnReportLoaded(ReportViewerOptions reportOption)
        {
            var reportParameters = ReportHelper.GetParameters(jsonArray, this, _cache);
            List<Syncfusion.Reporting.Web.ReportParameter> setParameters = new List<Syncfusion.Reporting.Web.ReportParameter>();

            if (reportParameters != null)
            {
                foreach (var rptParameter in reportParameters)
                {
                    setParameters.Add(new Syncfusion.Reporting.Web.ReportParameter()
                    {
                        Name = rptParameter.Name,
                        Values = new List<string>() { "SO50756" }
                    });
                }

                reportOption.ReportModel.Parameters = setParameters;
            }
        }
    }