Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Reports Viewer will not refresh

Status
Not open for further replies.

TonyFoo

Programmer
Jul 2, 2008
21
CA
Hi All, I am currently passing parameters (all blank strings right now except Offices to a Crystal Reports Viewer. The Crystal Reports Viewer will not refresh or even recognize that anything has changed. I am currently using VS 2005 and here is my code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

public partial class Test3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = ".";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "Kyle";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = "ISLDB";
CrystalReportViewer1.ReportSource = CrystalReportSource1;
if (!Page.IsPostBack)
{
//Load The Drop Down Lists
LoadOffices();
LoadBoxTypes();
LoadStatus();
ReportParameter();
}

}
protected void LoadOffices()
{
DataSet officeDS = new DataSet();
try
{

ISL_System.ISL controller = new ISL_System.ISL();
officeDS = controller.LookUpOfficeList();
DataRow blankRow = officeDS.Tables["OfficeDS"].NewRow();
blankRow["OfficeDescription"] = "";
blankRow["OfficeKey"] = 0;
officeDS.Tables["OfficeDS"].Rows.Add(blankRow);
officeDS.Tables["OfficeDS"].DefaultView.Sort = "OfficeDescription ASC";

ddlOfficeList.DataSource = officeDS.Tables["OfficeDS"];
ddlOfficeList.DataTextField = "OfficeDescription";
ddlOfficeList.DataValueField = "OfficeKey";
ddlOfficeList.DataBind();
}
catch (Exception ex)
{
lblMessage.Text = "error loading Offices" + ex.Message;
}
}
protected void LoadBoxTypes()
{
DataSet BoxTypeDS = new DataSet();
try
{

ISL_System.ISL controller = new ISL_System.ISL();
BoxTypeDS = controller.LookUpBoxTypeList();
DataRow blankRow = BoxTypeDS.Tables["BoxTypeDS"].NewRow();
blankRow["BoxTypeDescription"] = "";
blankRow["BoxTypeKey"] = 0;
BoxTypeDS.Tables["BoxTypeDS"].Rows.Add(blankRow);
BoxTypeDS.Tables["BoxTypeDS"].DefaultView.Sort = "BoxTypeDescription ASC";

ddlBoxTypeList.DataSource = BoxTypeDS.Tables["BoxTypeDS"];
ddlBoxTypeList.DataTextField = "BoxTypeDescription";
ddlBoxTypeList.DataValueField = "BoxTypeKey";
ddlBoxTypeList.DataBind();
}
catch (Exception ex)
{
lblMessage.Text = "error loading Box Types" + ex.Message;
}
}
protected void LoadStatus()
{
DataSet StatusDS = new DataSet();
try
{

ISL_System.ISL controller = new ISL_System.ISL();
StatusDS = controller.LookUpStatusList();
DataRow blankRow = StatusDS.Tables["StatusDS"].NewRow();
blankRow["StatusDescription"] = "";
blankRow["StatusKey"] = 0;
StatusDS.Tables["StatusDS"].Rows.Add(blankRow);
StatusDS.Tables["StatusDS"].DefaultView.Sort = "StatusDescription ASC";

ddlStatusList.DataSource = StatusDS.Tables["StatusDS"];
ddlStatusList.DataTextField = "StatusDescription";
ddlStatusList.DataValueField = "StatusKey";
ddlStatusList.DataBind();
}
catch (Exception ex)
{
lblMessage.Text = "error loading Status drop down list" + ex.Message;
}
}
private void ReportParameter()
{
CrystalReportViewer1.RefreshReport();
ParameterFields paramFields = new ParameterFields();
//Project Number parameter
ParameterField ProjectNumber = new ParameterField();
ProjectNumber.ParameterFieldName = "ProjectNumber"; //project number is Crystal Report Parameter name.
ParameterDiscreteValue dcProjectNumber = new ParameterDiscreteValue();

dcProjectNumber.Value = "";

ProjectNumber.CurrentValues.Add(dcProjectNumber);
paramFields.Add(ProjectNumber);
//Office Parameter
int intOffice = ddlOfficeList.SelectedIndex;
ParameterField Office = new ParameterField();
Office.ParameterFieldName = "Office"; //project number is Crystal Report Parameter name.
ParameterDiscreteValue dcOffice = new ParameterDiscreteValue();
dcOffice.Value = ddlOfficeList.SelectedItem.Text;//ddlOfficeList.SelectedValue;
Office.CurrentValues.Add(dcOffice);
paramFields.Add(Office);
//Box Type Parameter
ParameterField BoxType = new ParameterField();
BoxType.ParameterFieldName = "BoxType"; //project number is Crystal Report Parameter name.
ParameterDiscreteValue dcBoxType = new ParameterDiscreteValue();
dcBoxType.Value = "";
BoxType.CurrentValues.Add(dcBoxType);
paramFields.Add(BoxType);
//Box Number Parameter
ParameterField BoxNumber = new ParameterField();
BoxNumber.ParameterFieldName = "BoxNumber"; //project number is Crystal Report Parameter name.
ParameterDiscreteValue dcBoxNumber = new ParameterDiscreteValue();

dcBoxNumber.Value = "";

BoxNumber.CurrentValues.Add(dcBoxNumber);
paramFields.Add(BoxNumber);
//Status Parameter
ParameterField Status = new ParameterField();
Status.ParameterFieldName = "Status"; //project number is Crystal Report Parameter name.
ParameterDiscreteValue dcStatus = new ParameterDiscreteValue();
dcStatus.Value = "";
Status.CurrentValues.Add(dcStatus);
paramFields.Add(Status);
CrystalReportViewer1.ParameterFieldInfo = paramFields;

}
protected void btnGenerateArchivedProjectReport_Click(object sender, EventArgs e)
{
ReportParameter();
lblMessage.Text = "Report Submitted";
}
}

Let me know if I can provide any more details.

Thanks,

Tony
 
chances are it's caching the report somewhere.
also, you shouldn't need to add the parameters to the report. just reference them and add the current values.
CrystalReportViewer1.ParameterFieldInfo["name of parameter"].CurrentValues.Add(name of variable);
or something similar to that.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you Jason!

I changed the code to add the current values as suggested above. As well, I introduced a report document to bind the report to everytime i configure the report. This forces the report to refresh.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top