We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set Parameters to Report in ReportViewer at Runtime?

Platform: ASP.NET MVC (Classic) |
Control: ReportViewer |
Published Date: November 14, 2014 |
Last Revised Date: May 23, 2019
Tags: reportviewer

When you want to pass the report parameters to the RDL/RDLC reports programmatically while a report is being loaded and a sub report is being processed, Syncfusion ASP.NET MVC Classic version of ReportViewer has support to programmatically set report parameters to report and this section helps you in learning how to set parameters to report programmatically in ReportViewer control.

When you are new to ASP.NET MVC Classic version of ReportViewer, you can refer to the Getting Started with ASP.NET MVC Classic version of ReportViewer from the following article.

http://syncfusion.com/support/kb/2669

 

Set Parameters Programmatically to Report

You can add collection of report parameters programmatically using the ReportViewerModel’s Parameters property that is the list type of ReportParameter class. The ReportParameter contains Name, Values, Labels, and Nullable properties to specify name, values and labels of report parameter.

Use the following code to set parameters.

C#

    public class ReportViewerController : Controller
    {
        private ReportViewerModel GetInvoiceModel()
        {
            //Model data class for report viewer
            ReportViewerModel reportModel = new ReportViewerModel();
            //Set the ReportPath of the Report
            reportModel.ReportPath = HttpContext.Server.MapPath("~/App_Data/InvoiceTemplate.rdl");
            List<ReportParameter> parameters = new List<ReportParameter>();
            ReportParameter parameter = new ReportParameter();
            parameter.Name = "InvoiceID";
            parameter.Labels.Add("10250");
            parameter.Values.Add("10250");
            //Add parameter
            parameters.Add(parameter);
            //Set the parameter collection
            reportModel.Parameters = parameters;
            return reportModel;
        }
 
        public ActionResult Index()
        {
            //Assign the ReportViewerModel to ViewData for ReportViewer Control 
            ViewData["ReportModel"] = this.GetInvoiceModel();
            return View();
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(ReportViewerParams param)
        {
            //Process the report request from client and send the action result
            return new ReportViewerHtmlActionResult(this.GetInvoiceModel(), param);
        }
    }

 

Use the following code to set parameters for Sub Report.

C#

public class ReportViewerController : Controller
    {
        private ReportViewerModel GetReportModel ()
        {
            //Model data class for report viewer
            ReportViewerModel reportModel = new ReportViewerModel();
            //Set the ReportPath of the Report
            reportModel.ReportPath = HttpContext.Server.MapPath("~/App_Data/SubReport.rdlc");
            //Set the ProcessingMode of the Report 
            reportModel.ProcessingMode = ProcessingMode.Local; 
            //Hook event for SubReport Model
            reportModel.SubReport += model_subReport;
            return reportModel;
        }
        private void model_subReport(object sender, SubreportProcessingEventArgs e)
        {
            //Set the parameter collection
            e.Parameters = new ReportParameterInfoCollection();
            ReportParameterInfo parameter = new ReportParameterInfo();
            parameter.Name = "InvoiceID";
            parameter.Labels.Add("10250");
            parameter.Values.Add("10250");
            //Add parameter
            e.Parameters.Add(parameter);
        }
        public ActionResult Index()
        {
            //Assign the ReportViewerModel to ViewData for ReportViewer Control 
            ViewData["ReportModel"] = this. GetReportModel();
            return View();
        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(ReportViewerParams param)
        {
            //Process the report request from client and send the action result
            return new ReportViewerHtmlActionResult(this. GetReportModel (), param);
        }
    }

 

Demo Sample

You can download the Demo Sample from the following link.

http://www.syncfusion.com/downloads/support/directtrac/general/ReportViewerSample-2061069698.zip

Further References

You can find documentation and online demo samples for ASP.NET MVC Classic ReportViewer control from the following links.

http://help.syncfusion.com/asp.net%20mvc

http://mvc.syncfusion.com/demos/reporting/reportviewer

 

Newer ASP.NET MVC version of ReportViewer

You can try the newer version of MVC ReportViewer that is powered by JavaScript/HTML5. You can refer to the documentation and online demo samples for newer ASP.NET MVC ReportViewer control from the following links.

http://help.syncfusion.com/web

http://mvc.syncfusion.com/demos/web/ReportViewer/

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon