INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

CrystalReportViewer forgetting parameters when drilling down

CrystalReportViewer forgetting parameters when drilling down

(OP)
I've got a CrystalReportViewer which is showing a report. I'm passing two parameters to it which change the data. This works, unless you try to drill down into the report further, at which point it resets to the default parameters.

It's a bit like the reportviewer element refreshes itself and forgets everything. I did have a page_init method which attempted to push the values back in but I was getting object reference errors so had probably done it wrong.

What else should I try? Please see code below:

CODE --> C#

protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ReportSource"] != null)
            {
                CrystalReportViewer1.ReportSource = (ReportDocument)Session["ReportSource"];
            }
            else
            {
                ReportDocument reportDocument = new ReportDocument();
                reportDocument.Load(Server.MapPath("~/Report/In Out.rpt"));
                reportDocument.SetDatabaseLogon("user", "pass" ,@"server", "db"); //removed credentials !
                CrystalReportViewer1.ReportSource = reportDocument;
                Session["ReportSource"] = reportDocument;
    
            }
        }
        
        protected void butReport_Click(object sender, EventArgs e)
        {
            ReportDocument reportDocument = new ReportDocument();
            reportDocument.Load(Server.MapPath("./Report/In Out.rpt"));
              reportDocument.SetDatabaseLogon("user", "pass" ,@"server", "db"); //removed credentials !    
            ///Load Session variables with values from web-controls
            Session["@FromDate"] = ConvertToDateTime(Request.Form["StartDate"]);
            Session["@ToDate"] = ConvertToDateTime(Request.Form["EndDate"]);
            reportDocument.SetParameterValue("Start", Session["@FromDate"]);
            reportDocument.SetParameterValue("End", Session["@ToDate"]);
            CrystalReportViewer1.ReportSource = reportDocument;
        } 

My CR is embedded as follows

CODE --> ASP

<div align="center">
                <asp:TextBox ID="StartDate" runat="server" type="date" placeholder="e.g. 31/12/2014" ></asp:TextBox> 
                <asp:TextBox ID="EndDate" runat="server" type="date" placeholder="e.g. 31/12/2014" ></asp:TextBox>
                <asp:button runat="server" id="Submit" type="button" value="Show Report" Text="View Report" onclick="butReport_Click" /></div>
                       
            <div>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
                       AutoDataBind="True" EnableDatabaseLogonPrompt="False" 
                       GroupTreeImagesFolderUrl="" Height="940px" 
                       ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1411px" 
                       EnableParameterPrompt="False" ReuseParameterValuesOnRefresh="True" 
                       ReportSourceID="CrystalReportSource1" />
                   <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
                       <Report FileName="Report\In Out.rpt">
                       </Report>
                   </CR:CrystalReportSource>
    </div> 

RE: CrystalReportViewer forgetting parameters when drilling down

(OP)
Just incase anyone finds this, I fixed it via the following code

protected void Page_Load(object sender, EventArgs e)
{
if (Session["ReportSource"] != null)
CrystalReportViewer1.ReportSource = (ReportDocument)Session["ReportSource"];
}

protected void butReport_Click(object sender, EventArgs e)
{
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(Server.MapPath("./Report/In Out.rpt"));
reportDocument.SetDatabaseLogon(credentials removed);

///Load Session variables with values from web-controls
Session["@FromDate"] = ConvertToDateTime(Request.Form["StartDate"]);
Session["@ToDate"] = ConvertToDateTime(Request.Form["EndDate"]);
reportDocument.SetParameterValue("Start", Session["@FromDate"]);
reportDocument.SetParameterValue("End", Session["@ToDate"]);
CrystalReportViewer1.ReportSource = reportDocument;
Session["ReportSource"] = reportDocument;
}

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close