Search results
Suggest a FeaturePDF

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 a parameter with razor view

Report Viewer parameter property does not have support to create parameter collection with razor view. So, we have to create and assign the parameter with help of ViewBag as follows.

        public ActionResult Index()
        {
            List<BoldReports.Models.ReportViewer.ReportParameter> parameters = new List<BoldReports.Models.ReportViewer.ReportParameter>();
            parameters.Add(new BoldReports.Models.ReportViewer.ReportParameter()
            {
                Name = "SalesOrderNumber",
                Values = new List<string>(){ "SO50756" }
            });
            ViewBag.parameters = parameters;
            return View();
        }
<bold-report-viewer id="reportviewer1" report-service-url="../ReportApi" processing-mode="Remote" parameters="ViewBag.parameters" />

Set parameters in Web API Controller

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;
}

The Report Parameters name should be case sensitive

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 IWebHostEnvironment _hostingEnvironment;

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

        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, _cache);
            List<BoldReports.Web.ReportParameter> modifiedParameters = new List<BoldReports.Web.ReportParameter>();

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

                reportOption.ReportModel.Parameters = modifiedParameters;
            }
        }
    }

Set date range for date parameter

The properties MaxDateTime and MinDateTime in the parameterSettings are used to set date range for date parameters in a report.

Property Description
MaxDateTime Specify minimum range value of a date parameter
MinDateTime Specify maximum range value of a date parameter

Refer to the following code sample to set data range using parameterSettings in Report Viewer controller.

        public ActionResult Index()
        {
            ViewBag.parameterSettings = new BoldReports.Models.ReportViewer.ParameterSettings();
            ViewBag.parameterSettings.MaxDateTime = new DateTime(2003, 8, 22);
            ViewBag.parameterSettings.MinDateTime = new DateTime(2003, 4, 22);
            return View();
        }

Refer to the following code sample to set data range to the report viewer initialization.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" parameter-settings="ViewBag.parameterSettings"> </bold-report-viewer>

The above code sets date range for all the date parameters used in the report.

To set different date range for each date parameter used in the report, register the event beforeParameterAdd and specify range based on parameter name as in below code sample.

      <bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" report-path="product-line-sales.rdl" before-parameter-add="beforeParameterAdd"> </bold-report-viewer>
       <script type="text/javascript">
       function beforeParameterAdd(args) {
           if (args.parameterModel.Name === "StartDate") {
               args.parameterSettings.minDateTime = new Date("4/5/2003 5:00:00 AM");
               args.parameterSettings.maxDateTime = new Date("4/15/2003 5:00:00 AM");
            }
            if (args.parameterModel.Name === "EndDate") {
               args.parameterSettings.minDateTime = new Date("5/10/2003 5:00:00 AM");
               args.parameterSettings.maxDateTime = new Date("5/20/2003 5:00:00 AM");
            }
        }
</script>

Set date time display format for date parameter

The properties dateTimeFormat and timeDisplayFormat in the parameterSettings are used to set date and time format to be displayed in the DateTimePicker control in a report.

Format Display in DateTimePicker
Short Date and Time - d/M/yy h:mm tt 9/12/2014 2:04 PM
Medium Date - d MMM yy h:mm tt 12 Sep 14 2:04: PM
Full Date and short time - dddd, MMMM dd, yyyy HH:mm tt Friday, September 12,2014 2:04 PM
Full Date and Long Time - dddd, MMMM dd, yyyy HH:mm:ss tt Friday, September 12,2014 2:04:00 PM
UTC - yyyy-MM-dThh:mm:ssz 2014-09-12T2:04:00+5

Refer to the following code sample to set date and time format to be displayed, using parameterSettings in Report Viewer controller.

        public ActionResult Index()
        {
            ViewBag.parameterSettings = new BoldReports.Models.ReportViewer.ParameterSettings();
            ViewBag.parameterSettings.DateTimeFormat = "d/M/yyyy h:mm tt";
            ViewBag.parameterSettings.TimeDisplayFormat = "HH:mm";
            ViewBag.parameterSettings.TimeInterval = 60;
            return View();
        }

Refer to the following code sample to set date and time format to be displayed in the report viewer initialization.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" parameter-settings="ViewBag.parameterSettings"> </bold-report-viewer>

The above code sets date and time value to be display for all the date parameters used in the report.

To set different date and time value to be display for each date parameter used in the report, register the event beforeParameterAdd and specify date and time value based on parameter name as in below code sample.

      <bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" report-path="product-line-sales.rdl" before-parameter-add="beforeParameterAdd"> </bold-report-viewer>
       <script type="text/javascript">
       function beforeParameterAdd(args) {
           if (args.parameterModel.Name === "StartDate") {
               args.parameterSettings.dateTimeFormat = "d/M/yyyy h:mm tt";
               args.parameterSettings.timeDisplayFormat = "HH:mm";
               args.parameterSettings.timeInterval = 60;
            }
            if (args.parameterModel.Name === "EndDate") {
               args.parameterSettings.dateTimeFormat = "d/M/yyyy h:mm tt";
               args.parameterSettings.timeDisplayFormat = "HH:mm";
               args.parameterSettings.timeInterval = 60;}
        }
</script>

Change the Parameter drop-down height and width

The parameterSettings helps you to change the height and width of the parameter available in parameter panel.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" parameter-settings="ViewBag.parameterSettings"> </bold-report-viewer>
    public ActionResult Index()
    {
        ViewBag.parameterSettings = new BoldReports.Models.ReportViewer.ParameterSettings();
        ViewBag.parameterSettings.PopupHeight = "200px";
        ViewBag.parameterSettings.PopupWidth = "100px";
        return View();
    }

Hide a Parameter scroller

The enableparameterblockscroller helps you to hide the scrollbar in parameter panel.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" enable-parameter-block-scroller="true"> </bold-report-viewer>

Hide a Parameter Pane on load

The parameterSettings helps you to hide and show the parameter block.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" parameter-settings="ViewBag.parameterSettings"> </bold-report-viewer>
    public ActionResult Index()
    {
        ViewBag.parameterSettings = new BoldReports.Models.ReportViewer.ParameterSettings();
        ViewBag.parameterSettings.HideParameterBlock = true;
        return View();
    }

Change the Parameter Item Width and Label Width

The parameterSettings helps you to change the parameter Item width and label width.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" parameter-settings="ViewBag.parameterSettings"> </bold-report-viewer>
    public ActionResult Index()
    {
        ViewBag.parameterSettings = new BoldReports.Models.ReportViewer.ParameterSettings();
        ViewBag.parameterSettings.ItemWidth = "250px";
        ViewBag.parameterSettings.LabelWidth = "auto";
        return View();
    }

Access the hidden or internal parameter information

The accessInternalValue property in the parameterSettings helps you to expose the hidden or internal report parameter information used in report to the user.

<bold-report-viewer id="viewer" report-service-url="/api/ReportViewer" processing-mode="Remote" parameter-settings="ViewBag.parameterSettings"> </bold-report-viewer>
    public ActionResult Index()
    {
        ViewBag.parameterSettings = new BoldReports.Models.ReportViewer.ParameterSettings();
        ViewBag.parameterSettings.AccessInternalValue = true;
        return View();
    }

Set the report parameter visibility in Web API Controller

The Hidden property of ReportParameter allows you to show or hide the parameter at the top of the report viewer panel. The following code example shows hiding a report parameter in the Web API controller’s OnReportLoaded method.

    [NonAction]
    public void OnReportLoaded(ReportViewerOptions reportOption)
    {
        var reportParameters = ReportHelper.GetParameters(jsonArray, this, _cache);
        List<BoldReports.Web.ReportParameter> modifiedParameters = new List<BoldReports.Web.ReportParameter>();

        if (reportParameters != null)
        {
            foreach (var rptParameter in reportParameters)
            {
                modifiedParameters.Add(new BoldReports.Web.ReportParameter()
                {
                    Name = rptParameter.Name,
                    Hidden = true
                });
            }

            reportOption.ReportModel.Parameters = modifiedParameters;
        }
    }