Link to home
Create AccountLog in
Avatar of kenuk110
kenuk110

asked on

Crystal Reports Parameters not being used when printing from CrystalReportsViewer

Hi,

I have a number of Crystal Reports running from .Net 4 webpages, when I view the reports on screen using the CrystalReportsViewer and change the parameters it's all fine but when I try to either Export or Print the report it reverts back to using the parameter I last used when saving the actual report.

I have tried loads of things, not saving data in with the report, that just refreshes the page, setting refresh DB connections in the report and to be honest to many other things but I just can't get the report to use the parameter I select from the web page.

Any ideas on how to make it work? I have attached the report code from the aspx page and also the code from the .cs file that is attached just incase this gives anyone any clues.

Any help would be really appreciated.

Regards,

Ken

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using CrystalDecisions;

namespace TarweejV4.Internal.PO.Forms
{
    public partial class VMF1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void CrystalReportViewer1_Load(object sender, EventArgs e)
        {
            ReportDocument report = new ReportDocument();
            report.Load(Server.MapPath("~/Internal/PO/FORMS/VMF.rpt"));
            report.SetDatabaseLogon("sa", "password", @"192.168.100.56", "T1");
            CrystalReportViewer1.ReportSource = report;
           
        }
    }

Open in new window

<CR:CrystalReportSource ID="VMF" runat="server">
        <Report FileName="~\Internal\PO\Forms\VMF.rpt">
        </Report>
    </CR:CrystalReportSource>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
        AutoDataBind="true" ReportSourceID="VMF" 
        ToolPanelView="ParameterPanel" onload="CrystalReportViewer1_Load" 
        HasRefreshButton="True" HasCrystalLogo="False"/>
</asp:Content>

Open in new window

Avatar of Mike McCracken
Mike McCracken

If you are exporting or printing from th eviewer it causes a postback which you have to handle.
You need to save the parameter values in session variables and reload them before exporting the report.

mlmcc
Avatar of kenuk110

ASKER

Hi,

I see, the next question is do you know how to do this, I'm not a programmer to be honest, do you have any advice on how I do this or a page on the net I could read??

Thanks in advance.

Ken
Hi mimcc,

Do you have any references I can try to use to figure this out, I understand what you are telling me but I'm at a loss how to proceed, I just don't know how to program this, I can however follow instruction and pass back information if that helps?

Regards,

Ken
I am not a .Net programmer so I haven't had to del with the issue.  I'll try to find sample code.

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks mimcc, I downloaded that PDF, printed it then found the place relating to Sessions. I clicked and deleted and edited and built 1000 times then finaly I got it working. Here is what I had to do just incase anyone else has this problem:

 protected void CrystalReportViewer1_Load(object sender, EventArgs e)
         {
            if (Session["Session"] == null)
            {
                ReportDocument DCS = new ReportDocument();
                DCS.Load(Server.MapPath("~/Internal/PO/FORMS/DCS.rpt"));
                DCS.SetDatabaseLogon("sa", "password", @"192.168.100.10", "T1");
                CrystalReportViewer1.ReportSource = DCS;
                Session["Session"] = DCS;
            }
            else
            {
                ReportDocument DCS = (ReportDocument)Session["Session"];
                DCS.Load(Server.MapPath("~/Internal/PO/FORMS/DCS.rpt"));
                DCS.SetDatabaseLogon("sa", "password", @"192.168.100.10", "T1");
                CrystalReportViewer1.ReportSource = DCS;
            }

        }


You have to add the report to a session, if it's null then build it as is but save it then it uses the parameters you selected throughout your time looking at the report, printing and exporting works perfectly now.

Thanks so much for you post.