简体   繁体   中英

how to refresh data in reportviewer?

I have a reportviewer in a webform named WebForm1 using 2 parameters named fromDate and toDate to filter data. The webform shows data when it loads. Problem is that when I change the fromDate , toDate field and click button1 to submit, it goes back to default date and reload with the same data. How do I refresh the reportviewer data with the new input date? How do I use reportviewer in a webform (not winform) with parameters? Thanks for any help.

Here is my WebForm1.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page

    { 
        protected void Page_Load(object sender, EventArgs e)
        {
            this.fromDate.Text = "8/6/2015";
            this.toDate.Text = DateTime.Now.ToShortDateString();
        }
    }
}

In the above scenario you are manualy assign fromDate and toDate values and reload it. No need to assign like that. You can get values from client side text box by using "fromDate.Text". Then pass those values into your method and return correct data to page.

You can set SSRS report parameter from web page as below

 string reportPath ="Report relative path"
                // Set the processing mode for the ReportViewer to Remote
                ReportViewer1.ProcessingMode = ProcessingMode.Remote;
                ServerReport serverReport = ReportViewer1.ServerReport;

                string reportserver = ConfigurationManager.AppSettings["ReportServer"];
                string username = ConfigurationManager.AppSettings["Username"];
                string password = ConfigurationManager.AppSettings["Password"];
                string domain = ConfigurationManager.AppSettings["Domain"];

                // Set the report server URL and report path
                serverReport.ReportServerUrl = new Uri(reportserver);
                serverReport.ReportServerCredentials = new ReportViewerCredentials(username, password, domain);
                serverReport.ReportPath = reportPath;


ReportParameter[] parameters;
                    parameters = new ReportParameter[2];
                    parameters[0] = new ReportParameter("fromDate", "8/6/2015");
                    parameters[1] = new ReportParameter("toDate", DateTime.Now.ToShortDateString());
                    ReportViewer1.ServerReport.SetParameters(parameters); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM