使用Visual Studio 2010和Crystal Reports 13.0。清除水晶报表参数
对于报告,提示用户输入一个值。然后生成报告没有问题。
如果用户离开report.aspx页面并返回运行另一个报表,则不会显示提示,并且上次运行的报表仍然存在,并且用户的原始值仍然存在。
搜索周围的解决方案,发现仅有的两个没有工作:
//After the report loads
CrystalReportSource1.ReportDocument.ParameterFields.Clear();
错误:
您不能添加,删除或修改使用此方法的参数字段。请直接修改报告。
直接修改报告:
右键点击你的水晶报表 的身体,然后转到:
设计 - >默认设置。 - >报告
选中该复选框
加载报告时放弃保存的数据。
这没有奏效。之前的报告仍然存在。
因此,我现在要求了解一下如何解决这个问题。
一如既往,欢迎任何建议。
感谢
编辑:
这里是落后的报告页面的代码。许多报告使用此页面....
CrystalReportSource1.Report.FileName = "reports\\" + fileName + ".rpt";
//CrystalReportSource1.Report.Parameters.Clear();
//CrystalReportSource1.Report = null;
//CrystalReportSource1.Report.Refresh();
if (!string.IsNullOrEmpty(Request.QueryString["item"]))
{
String Item = Request.QueryString["item"];
CrystalDecisions.Web.Parameter temp = new CrystalDecisions.Web.Parameter();
temp.Name = "Item";
temp.DefaultValue = Item;
CrystalReportSource1.Report.Parameters.Add(temp);
}
SqlConnectionStringBuilder settings = new SqlConnectionStringBuilder(MyConnectionString);
_crReportDocument = CrystalReportSource1.ReportDocument;
_crConnectionInfo.ServerName = settings.DataSource;
_crConnectionInfo.DatabaseName = settings.InitialCatalog;
_crConnectionInfo.UserID = settings.UserID;
_crConnectionInfo.Password = settings.Password;
//Get the table information from the report
_crDatabase = _crReportDocument.Database;
_crTables = _crDatabase.Tables;
//Loop through all tables in the report and apply the
//connection information for each table.
for (int i = 0; i < _crTables.Count; i++)
{
_crTable = _crTables[i];
_crTableLogOnInfo = _crTable.LogOnInfo;
_crTableLogOnInfo.ConnectionInfo = _crConnectionInfo;
_crTable.ApplyLogOnInfo(_crTableLogOnInfo);
}
很抱歉,在所有加载后,Page_Unload事件都会触发;因此,它将在可以查看之前关闭/处理报告。 –
我刚刚看到您添加到问题中的代码。你为什么评论第2至第4行?这应该照顾它 - >清除Page_Load上的所有内容,然后加载报告。 –
我注释掉的行不起作用,但我将它们留在那里,所以我不再尝试它们。 –