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.
Unfortunately, activation email could not send to your email. Please try again.

ReportViewer's parameter on View Report click event

Thread ID:

Created:

Updated:

Platform:

Replies:

131662 Jul 21,2017 12:16 PM Jul 26,2017 06:10 AM ASP.NET Web Forms 3
loading
Tags: ReportViewer
Sam
Asked On July 21, 2017 12:16 PM

Hello,

How to I get report parameters from the ReportViewer control after clicked on View Report button.  I cannot find a server event for "View Report" button

<form id="form1" runat="server">
        <asp:ScriptManager runat="server" />        
        <div id="reportviewer">
            <ej:ReportViewer ID="viewer" runat="server" PrintMode="false"></ej:ReportViewer>
        </div>
    </form>

Code Behind:
viewer.Visible = true;
var rpt = new AnnualWorkloadRep2014(2014, 53); // I want to pass dynamic values from report viewer's parameter control
 
            viewer.ProcessingMode = Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Local;
            viewer.ReportPath = rpt.ReportPath;
            viewer.ReportServiceUrl = "api/reportapi";
            viewer.DataSources = rpt.SfGetDataSources();
 
            var caseYear = new Syncfusion.JavaScript.Models.ReportViewer.ReportParameter() { Name = "CaseYear", Prompt = "Case Year", Labels = null, Values = new List<string> { "2014" }, Nullable = false };
            var countyId = new Syncfusion.JavaScript.Models.ReportViewer.ReportParameter() { Name = "CountyId", Prompt = "County ID", Labels = null, Values = new List<string> { "53" }, Nullable = false };
 
            var list = new List<Syncfusion.JavaScript.Models.ReportViewer.ReportParameter>();
list.Add(caseYear);
list.Add(countyId);
viewer.Parameters.AddRange(list);

Hope I described it clearly.
Appreciate your help.     


Ravi Kumar Gurunathan [Syncfusion]
Replied On July 24, 2017 09:38 AM

Hi Sam, 
 
Thanks for contacting Syncfusion support. 
 
How to I get report parameters from the ReportViewer control after clicked on View Report button.  I cannot find a server event for "View Report" button 
We can get the available list of report parameters and its values in the script block after clicked the “View Report button” through click event as shown in below code snippet. Also, the dynamically assigned parameter values should be passed into the reportviewer control through “ajax call” as provided in the below sample. 
ej.ReportViewer.prototype._viewReportParamsClick = function (event) { 
            var proxy = $('#ReportViewer1').data('ejReportViewer'); 
            var parameters = event.data.params; 
            var reportParams = proxy._getParameterJson(parameters); 
            proxy._refresh = true; 
            $('#' + proxy._id + '_viewBlockContainer .e-reportviewer-viewerblockcontent table:first')    .attr('isviewclick', 'true'); 
            _params = []; 
            _params.push({ Name: 'StateProvinceCode', Values: ['TX'], Labels: ['TX'] }); 
            proxy._refreshReport(); 
        } 
 
I want to pass dynamic values from report viewer's parameter control 
The dynamic parameter values can be handled at code behind (WebApi controller) to filter the RDLC datasource values and assigned into the report parameters as shown in below code snippet. 
var parameters = new List<Syncfusion.Reports.EJ.ReportParameter>(); 
            if (System.Web.HttpContext.Current.Items.Contains("parakey")) 
            { 
                parameters = new System.Web.Script.Serialization.JavaScriptSerializer(). 
Deserialize<List<Syncfusion.Reports.EJ.ReportParameter>>(System.Web.HttpContext.Current.Items["parakey"].ToString()); 
                System.Web.HttpContext.Current.Items.Remove("parakey"); 
            } 
 
            reportOption.ReportModel.Parameters = parameters; 
            if(parameters != null && parameters.Count > 0) 
            { 
                reportOption.ReportModel.DataSources.Clear(); 
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData(parameters[0].Values[0]) });   
            } 
            else 
            { 
                reportOption.ReportModel.DataSources.Clear(); 
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData("GA") });   
            } 
 
However, we have prepared a sample based on your scenario and it can be downloaded from the below link. 
 
Ravi kumar G 
 


Sam
Replied On July 25, 2017 04:14 PM

Hello,

I have tried out your code and got it to work, but I came up another problem that how do I pass parameters from Report Initial Load because the Get Method would not execute when report loading. I don't want to hard-code the values when report loaded the first time.

Code Behind:

public class ReportApiController : ApiController, IReportController

    {

        object reportDataSources;

        DataTable rs;

        DataTable rs1;

        DataTable rs2;


        // GET api/<controller>

        public IEnumerable<string> Get()

        {

            return new string[] { "value1", "value2" };

        }


        // GET api/<controller>/5

        public string Get(string id)

        {

            return "value";

        }


        // POST api/<controller>

        public void Post([FromBody]string value)

        {

        }


        // PUT api/<controller>/5

        public void Put(int id, [FromBody]string value)

        {

        }


        // DELETE api/<controller>/5

        public void Delete(int id)

        {

        }


        //Post action for processing the rdl/rdlc report

        public object PostReportAction(Dictionary<string, object> jsonResult)

        {

            //if (jsonResult.ContainsKey("dataSources"))

            //{

            //    reportDataSources = jsonResult["dataSources"];

            //    var a = JArray.Parse(reportDataSources.ToString());

            //    // var b = (JObject)JsonConvert.DeserializeObject(reportDataSources.ToString());




            //    rs = JsonConvert.DeserializeObject<DataTable>(a[0]["value"].ToString());

            //    rs1 = JsonConvert.DeserializeObject<DataTable>(a[1]["value"].ToString());

            //    rs2 = JsonConvert.DeserializeObject<DataTable>(a[2]["value"].ToString());


            //}


            if (jsonResult.ContainsValue("GetDataSourceCredential") && jsonResult.ContainsKey("params"))

            {

                System.Web.HttpContext.Current.Items.Add("parakey", jsonResult["params"]);

            } 


            return ReportHelper.ProcessReport(jsonResult, this);

        }

        //Get action for getting resources from the report

        [System.Web.Http.ActionName("GetResource")]

        [AcceptVerbs("GET")]

        public object GetResource(string key, string resourcetype, bool isPrint)

        {

            return ReportHelper.GetResource(key, resourcetype, isPrint);

        }


        /// <summary>

        /// Method will be called when initialize the report options before start processing the report

        /// Report Initialization method that is triggered when report begins to be processed.

        /// </summary>

        /// <param name="reportOptions">The ReportViewer options.</param>

        public void OnInitReportOptions(ReportViewerOptions reportOptions)

        {

            //You can update report options here

            //List<Syncfusion.Reports.EJ.ReportParameter> parameters = new List<Syncfusion.Reports.EJ.ReportParameter>();

            //parameters.Add(new Syncfusion.Reports.EJ.ReportParameter() { Prompt= "Comments", Nullable=true, Name = "Comments", Labels = new List<string>() { "Comments" } });

            //reportOptions.ReportModel.Parameters = parameters;



        }


        /// <summary>

        /// Method will be called when reported is loaded

        /// Report loaded method that is triggered when report and sub report are loaded.

        /// </summary>

        /// <param name="reportOptions">The ReportViewer options.</param>

        public void OnReportLoaded(ReportViewerOptions reportOptions)

        {


            ////You can update report options here

            ////Adds data sources to report model.

            //reportOptions.ReportModel.DataSources.Clear();            


            var rpt = new AnnualWorkloadRep2014(2014, 53);

            var ds = new DataSet();

            ds = rpt.GetDataSource();


            var parameters = new List<Syncfusion.Reports.EJ.ReportParameter>();

            if (System.Web.HttpContext.Current.Items.Contains("parakey"))

            {

                parameters = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<Syncfusion.Reports.EJ.ReportParameter>>(System.Web.HttpContext.Current.Items["parakey"].ToString());

                System.Web.HttpContext.Current.Items.Remove("parakey");

            }

// Parameters variable always Zero for the initial loaded.

            reportOptions.ReportModel.Parameters = parameters;

            if (parameters != null && parameters.Count > 0)

            {

                reportOptions.ReportModel.DataSources.Clear();

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsDeathInvestigatedCertified", Value = ds.Tables["DeathInvestigatedCertified"] });

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsSIDS", Value = ds.Tables["SIDSTable"] });

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsJD", Value = ds.Tables["JDCases"] });

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsFetalDeaths", Value = ds.Tables["FetalDeaths"] });

            }

            else

            {

                reportOptions.ReportModel.DataSources.Clear();

                

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsDeathInvestigatedCertified", Value = ds.Tables["DeathInvestigatedCertified"] });

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsSIDS", Value = ds.Tables["SIDSTable"] });

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsJD", Value = ds.Tables["JDCases"] });

                reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsFetalDeaths", Value = ds.Tables["FetalDeaths"] });


                var caseYear = new Syncfusion.Reports.EJ.ReportParameter() { Name = "CaseYear", Prompt = "Case Year", Labels = new List<string> { "CaseYear" }, Values = new List<string> { "2014" }, Nullable = false };

                var countyId = new Syncfusion.Reports.EJ.ReportParameter() { Name = "CountyId", Prompt = "County ID", Labels = new List<string> { "CountyId" }, Values = new List<string> { "53" }, Nullable = false };


                List<Syncfusion.Reports.EJ.ReportParameter> list = new List<Syncfusion.Reports.EJ.ReportParameter>();

                list.Add(caseYear);

                list.Add(countyId);


                reportOptions.ReportModel.Parameters = list;

            }


        }

    }


Thank you for your help

-Sam


Yuvaraj Devarajan [Syncfusion]
Replied On July 26, 2017 06:10 AM

Hi Sam, 

We can able to add/pass the default value for the Report Parameter in the page_Load method while initializing the ReportViewer control in Default.apax.cs page as shown in below code example, 

Index.cshtml 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            viewer.Parameters = new List<ReportParameter>(); 
            viewer.Parameters.Add(new ReportParameter() 
            { 
                Name = "InvoiceID", 
                Labels = new List<string>() { "InvoiceID" }, 
                Values = new List<string>() { "10250" } 
            }); 
        } 

Please refer to the below UG documentation link for more detail, 

Regards, 
Yuvaraj D. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;