This snippet of code allows you to show a report dynamically using the Report control with Reporting Services and ASP.NET (C#):

        protected void Page_Load(object sender, EventArgs e)
        {
            reportServerUrl = "<report server>"; // e.g. localhost
            reportPath = "/path/to/report";
            reportViewer = "sdsdffsd";

            if (!IsPostBack)
            {
                this.ReportViewer1.ServerReport.ReportServerUrl = new System.Uri(reportServerUrl);
                this.ReportViewer1.ServerReport.ReportPath = reportPath;

                Microsoft.Reporting.WebForms.ReportParameter[] RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[3];
                RptParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("From", "01-01-2011"); // any param
                RptParameters[1] = new Microsoft.Reporting.WebForms.ReportParameter("To", "01-01-2011"); // any param
                RptParameters[2] = new Microsoft.Reporting.WebForms.ReportParameter("Links", "True"); // any param

                this.ReportViewer1.ServerReport.SetParameters(RptParameters);
                this.ReportViewer1.ServerReport.Refresh();
            }
        }

Your parameters will be different than mine, you can remove those, or edit them. This code assumes your Report Viewer control is called ReportViewer1.

Tags: , , , , ,

· · · ◊ ◊ ◊ · · ·