Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Dynamically change Crystal Report Viewer source

Dynamically change Crystal Report Viewer source

Scheduled Pinned Locked Moved C#
database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jamesc69
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • J jamesc69

      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

      R Offline
      R Offline
      Rajasekhar Reddy Adam
      wrote on last edited by
      #2

      Hi James if want to pass same vaules to multiple times just save that values in cache and pass them when it required

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups