locked
Pass parameter to .RDL on ASP.Net Page load RRS feed

  • Question

  • User1143579256 posted

    Hi All,

      I need help in passing parameter to .rdl reports from ASP.NET page, below is my code. I am not getting any error and also its not disply my report too.

    Pls do help to disply rdl report using reportviewer in asp.net passing parameter in page load.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.Reporting.WebForms;

    namespace reporting.Web
    {
        public partial class ReportViewer : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

                MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                //MyReportViewer.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();
                MyReportViewer.ServerReport.ReportServerUrl = new Uri(@"http://gblon9sqm10/ReportServer_DB10");
                MyReportViewer.ServerReport.ReportPath = "/Reports/parameter_report";
                MyReportViewer.ShowParameterPrompts = false;
                MyReportViewer.ShowPrintButton = true;
               

                ReportParameter[] rptParams = new ReportParameter[1];
                rptParams[0] = new ReportParameter("exposureType", "Impressions");
                //rptParams[1] = new ReportParameter("param1", "value");
                //rptParams[2] = new ReportParameter("param3", "value");
                MyReportViewer.ServerReport.SetParameters(rptParams);
                MyReportViewer.ServerReport.Refresh();
                MyReportViewer.AsyncRendering = false;
                MyReportViewer.SizeToReportContent = true;

          }
        }
    }

    Thanks in advance and waiting for reply and help.

    Regards,

    Raju

    Monday, June 6, 2011 5:27 AM

Answers

  • User1471008070 posted

    Hi Magadiraju,

    Your issue has no relationship with ReportViewer.ShowParameterPrompts = false, The problem is you need to add your codes under IsPostBack wrapping, so please modify your code just like below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.Reporting.WebForms;
    
    namespace reporting.Web
    {
        public partial class ReportViewer : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack)
                {
    
                MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                //MyReportViewer.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();
                MyReportViewer.ServerReport.ReportServerUrl = new Uri(@"http://gblon9sqm10/ReportServer_DB10");
                MyReportViewer.ServerReport.ReportPath = "/Reports/parameter_report";
                MyReportViewer.ShowParameterPrompts = false;
                MyReportViewer.ShowPrintButton = true;
               
    
                ReportParameter[] rptParams = new ReportParameter[1];
                rptParams[0] = new ReportParameter("exposureType", "Impressions");
                //rptParams[1] = new ReportParameter("param1", "value");
                //rptParams[2] = new ReportParameter("param3", "value");
                MyReportViewer.ServerReport.SetParameters(rptParams);
                MyReportViewer.ServerReport.Refresh();
                MyReportViewer.AsyncRendering = false;
                MyReportViewer.SizeToReportContent = true;
                }
    
          }
        }
    }
    
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 9, 2011 4:35 AM

All replies

  • User-1886250979 posted

    I think you have to change your parameter count  as :

     ReportParameter[] rptParams = new ReportParameter[2];
                rptParams[0] = new ReportParameter("exposureType", "Impressions");
                //rptParams[1] = new ReportParameter("param1", "value");
                //rptParams[2] = new ReportParameter("param3", "value");

    Monday, June 6, 2011 5:32 AM
  • User1143579256 posted

    Why parameter count to be 2? i am sending only one parameter in my code other 2 are commented?

    Monday, June 6, 2011 7:28 AM
  • User-1886250979 posted

    I am posting my code. It was working fine for me....

    Microsoft.Reporting.WebForms.ReportParameter[] reportParameters = new Microsoft.Reporting.WebForms.ReportParameter[7];

    reportName = "PreAuthRequestForaPeriod";
    reportParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("HospitalId", hospitalId);
    reportParameters[1] = new Microsoft.Reporting.WebForms.ReportParameter("CorporateId", corporateId);
    reportParameters[2] = new Microsoft.Reporting.WebForms.ReportParameter("TPAID", TPAID);
    reportParameters[3] = new Microsoft.Reporting.WebForms.ReportParameter("FromDate", fromDate);
    reportParameters[4] = new Microsoft.Reporting.WebForms.ReportParameter("ToDate", toDate);
    reportParameters[5] = new Microsoft.Reporting.WebForms.ReportParameter("caseStatus", caseStatus);
    reportParameters[6] = new Microsoft.Reporting.WebForms.ReportParameter("Header", header);
    GenerateReport(reportName, reportParameters);
    
    
    private void GenerateReport(string reportName, ReportParameter[] reportParameters)
    {

    string reportServerUrl = ConfigurationManager.AppSettings["ReportServerUrl"];
    string reportPath = ConfigurationManager.AppSettings["ReportFolder"] + "/" + reportName;

    ReportViewerPatientDetails.ServerReport.ReportServerUrl = new Uri(reportServerUrl);
    ReportViewerPatientDetails.ServerReport.ReportPath = reportPath;
    ReportViewerPatientDetails.ServerReport.SetParameters(reportParameters);
    ReportViewerPatientDetails.ServerReport.Refresh();

    ReportViewerPatientDetails.Attributes.Add("style", "margin-bottom: 50px;");
    }
    Monday, June 6, 2011 7:34 AM
  • User1143579256 posted

    Hi Sreenivas,

    Thanks for your kind reply, still its not working for me. And i have few clarification, could you please clarify the same.

    1. Are you using .RDL reports and they are published in report server? (not .RDLC report and those are not part of my application folder).

    2. Which version of Reportviewer you are using?

    3. Are you setting the "ReportViewer.ShowParameterPrompts = false;" other wise we will get the parameter options in reportviewer also?

    And below are the my steps:

    I have created Application to view .RDL reports published in the report server, using ASP.NET 4.0 and Reportvivwer10 for Visual studio 2010.

    T

    Tuesday, June 7, 2011 7:20 AM
  • User1471008070 posted

    Hi Magadiraju,

    Your issue has no relationship with ReportViewer.ShowParameterPrompts = false, The problem is you need to add your codes under IsPostBack wrapping, so please modify your code just like below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.Reporting.WebForms;
    
    namespace reporting.Web
    {
        public partial class ReportViewer : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack)
                {
    
                MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                //MyReportViewer.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();
                MyReportViewer.ServerReport.ReportServerUrl = new Uri(@"http://gblon9sqm10/ReportServer_DB10");
                MyReportViewer.ServerReport.ReportPath = "/Reports/parameter_report";
                MyReportViewer.ShowParameterPrompts = false;
                MyReportViewer.ShowPrintButton = true;
               
    
                ReportParameter[] rptParams = new ReportParameter[1];
                rptParams[0] = new ReportParameter("exposureType", "Impressions");
                //rptParams[1] = new ReportParameter("param1", "value");
                //rptParams[2] = new ReportParameter("param3", "value");
                MyReportViewer.ServerReport.SetParameters(rptParams);
                MyReportViewer.ServerReport.Refresh();
                MyReportViewer.AsyncRendering = false;
                MyReportViewer.SizeToReportContent = true;
                }
    
          }
        }
    }
    
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 9, 2011 4:35 AM