Symptom
- Create a Web application to display Crystal report using Visual Studios 2008 .
- The report has a parameter and multiple pages.
- When next button in the viewer tool is pressed the parameter needs to be passed again.
Environment
- Visual Studios 2008.
- Crystal Reports 2008.
- Web application is created in C#.
Reproducing the Issue
The following code(C#) is used in the application:
public partial class DailySummaryDisplay : System.Web.UI.Page
{
ReportDocument dailyReportSummary = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CrystalReportViewer1.Visible = false;
}
else
if (CrystalReportViewer1.Visible == true)
{
BindReport();
}
}
protected void btnPreview_Click(object sender, EventArgs e)
{
BindReport();
CrystalReportViewer1.Visible = true;
}
private void BindReport()
{
dailyReportSummary.Load(Server.MapPath("~/Reports/DailySummary.rpt"));
dailyReportSummary.SetDataSource((DataTable)ta.GetAllTransactions());
CrystalReportViewer1.DisplayGroupTree = false;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasPrintButton = false;
CrystalReportViewer1.HasExportButton = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.ReportSource = dailyReportSummary;
}
public void Page_Unload(object sender, EventArgs e)
{
//Clean up resources. Force garbage collection.
dailyReportSummary.Close();
dailyReportSummary.Dispose();
GC.Collect();
}
System.IO.Stream stream = reportDocument.ExportToStream (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Cause
- Viewer is not being made visible in postback.
- Parameters are not passed through code.
Resolution
Changes made in the following Section:
A) Page_Load event:
ReportDocument dailyReportSummary = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CrystalReportViewer1.Visible = false;
}
else
//Code removed.
//if (CrystalReportViewer1.Visible == true)
{
CrystalReportViewer1.Visible = true;
BindReport();
}
}
B) Parameter is passed in the BindReport() method:
private void BindReport()
{
dailyReportSummary.Load(Server.MapPath("Product Catalog.rpt"));
dailyReportSummary.FileName = Server.MapPath("Product Catalog.rpt");
/// PASSING THE PARAMETER VALUE
dailyReportSummary.SetParameterValue("My Parameter", "MyParameterValue");
CrystalReportViewer1.DisplayGroupTree = false;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasPrintButton = false;
CrystalReportViewer1.HasExportButton = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.ReportSource = dailyReportSummary;
}
See Also
Keywords
dot net, vs, sdk, api , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem
Product
Crystal Reports 2008 V1 ; SAP Crystal Reports, version for Visual Studio .NET 2008