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:
My CR is embedded as follows
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:
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:
<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>