Dynamically change Crystal Report Viewer source
-
Hi, I've written a number of Crystal reports, and I would like to get my report viewer to bind the report on change of dropdown. This does work, however for each one change it asks for the parameter information again. Below is my source - the parameters are the same across all reports and are held in session: protected void Page_Load(object sender, EventArgs e) { if ((ViewState["ParametersShown"] != null) && (ViewState["ParametersShown"].ToString() == "True")) { ReportListing myListing = new ReportListing(); BindReport("MYPATH" + myListing.GetReportFileName(Session["Report"].ToString())); } } protected void btnBuild_Click(object sender, EventArgs e) { DateTime startDate = DateTime.Parse(Session["FromDate"].ToString()); DateTime endDate = DateTime.Parse(Session["ToDate"].ToString()); ParameterFields paramFields = new ParameterFields(); ParameterField crStartDate = new ParameterField(); ParameterField crEndDate = new ParameterField(); crStartDate.Name = "@StartDate"; crEndDate.Name = "@EndDate"; ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue(); ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue(); dcrStartDate.Value = startDate; dcrEndDate.Value = endDate; crStartDate.CurrentValues.Add(dcrStartDate); crEndDate.CurrentValues.Add(dcrEndDate); paramFields.Add(crStartDate); paramFields.Add(crEndDate); CrystalReportViewer1.ParameterFieldInfo = paramFields; ReportListing myListing = new ReportListing(); BindReport("MYPATH" + myListing.GetReportFileName(Session["Report"].ToString())); ViewState["ParametersShown"] = "True"; } private void BindReport(string FilePath) { ReportDocument Report = new ReportDocument(); Report.Load(FilePath); SetTableLocation(Report.Database.Tables); CrystalReportViewer1.ReportSource = Report; } private void SetTableLocation(Tables tables) { ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.ServerName = ConfigurationManager.AppSettings["ReportDBServerName"].ToString(); connectionInfo.DatabaseName = ConfigurationManager.AppSettings["ReportDBDBName"].ToString(); connectionInfo.UserID = ConfigurationManager.AppSettings["ReportDBUserID"].ToString(); connection
-
Hi, I've written a number of Crystal reports, and I would like to get my report viewer to bind the report on change of dropdown. This does work, however for each one change it asks for the parameter information again. Below is my source - the parameters are the same across all reports and are held in session: protected void Page_Load(object sender, EventArgs e) { if ((ViewState["ParametersShown"] != null) && (ViewState["ParametersShown"].ToString() == "True")) { ReportListing myListing = new ReportListing(); BindReport("MYPATH" + myListing.GetReportFileName(Session["Report"].ToString())); } } protected void btnBuild_Click(object sender, EventArgs e) { DateTime startDate = DateTime.Parse(Session["FromDate"].ToString()); DateTime endDate = DateTime.Parse(Session["ToDate"].ToString()); ParameterFields paramFields = new ParameterFields(); ParameterField crStartDate = new ParameterField(); ParameterField crEndDate = new ParameterField(); crStartDate.Name = "@StartDate"; crEndDate.Name = "@EndDate"; ParameterDiscreteValue dcrStartDate = new ParameterDiscreteValue(); ParameterDiscreteValue dcrEndDate = new ParameterDiscreteValue(); dcrStartDate.Value = startDate; dcrEndDate.Value = endDate; crStartDate.CurrentValues.Add(dcrStartDate); crEndDate.CurrentValues.Add(dcrEndDate); paramFields.Add(crStartDate); paramFields.Add(crEndDate); CrystalReportViewer1.ParameterFieldInfo = paramFields; ReportListing myListing = new ReportListing(); BindReport("MYPATH" + myListing.GetReportFileName(Session["Report"].ToString())); ViewState["ParametersShown"] = "True"; } private void BindReport(string FilePath) { ReportDocument Report = new ReportDocument(); Report.Load(FilePath); SetTableLocation(Report.Database.Tables); CrystalReportViewer1.ReportSource = Report; } private void SetTableLocation(Tables tables) { ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.ServerName = ConfigurationManager.AppSettings["ReportDBServerName"].ToString(); connectionInfo.DatabaseName = ConfigurationManager.AppSettings["ReportDBDBName"].ToString(); connectionInfo.UserID = ConfigurationManager.AppSettings["ReportDBUserID"].ToString(); connection
Hi James if want to pass same vaules to multiple times just save that values in cache and pass them when it required