C# 透明水晶报表参数

C# 透明水晶报表参数,c#,asp.net,crystal-reports,C#,Asp.net,Crystal Reports,使用Visual Studio 2010和Crystal Reports 13.0 对于报告,会提示用户输入值。然后生成报告,没有问题 如果用户离开report.aspx页面并返回运行另一个报表,则不会显示提示,并且最后一次运行的报表仍然存在,并保留用户提供的原始值 在四处搜索解决方案时,仅找到两个解决方案无效: //After the report loads CrystalReportSource1.ReportDocument.ParameterFields.Clear(); 错误:

使用Visual Studio 2010和Crystal Reports 13.0

对于报告,会提示用户输入值。然后生成报告,没有问题

如果用户离开report.aspx页面并返回运行另一个报表,则不会显示提示,并且最后一次运行的报表仍然存在,并保留用户提供的原始值

在四处搜索解决方案时,仅找到两个解决方案无效:

 //After the report loads
 CrystalReportSource1.ReportDocument.ParameterFields.Clear();
错误:

不能使用此方法添加、删除或修改参数字段。请直接修改报告

直接修改报告:

右键单击Crystal报告的正文 然后转到:

设计->默认设置..->报告

选中复选框

加载报告时放弃保存的数据

这不起作用。上一个报告仍在填充

所以,我现在想了解一下如何解决这个问题

一如既往,欢迎提出任何建议

谢谢

编辑:

下面是报告页面的代码。许多报告使用此页面

            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);
            }
CrystalReportSource1.Report.FileName=“reports\\”+FileName+“.rpt”;
//CrystalReportSource1.Report.Parameters.Clear();
//CrystalReportSource1.Report=null;
//CrystalReportSource1.Report.Refresh();
如果(!string.IsNullOrEmpty(Request.QueryString[“item”]))
{
String Item=Request.QueryString[“Item”];
CrystalDecisions.Web.Parameter temp=新的CrystalDecisions.Web.Parameter();
temp.Name=“项目”;
temp.DefaultValue=项目;
CrystalReportSource1.Report.Parameters.Add(临时);
}
SqlConnectionStringBuilder设置=新建SqlConnectionStringBuilder(MyConnectionString);
_crReportDocument=CrystalReportSource1.ReportDocument;
_crConnectionInfo.ServerName=settings.DataSource;
_crConnectionInfo.DatabaseName=settings.InitialCatalog;
_crConnectionInfo.UserID=settings.UserID;
_crConnectionInfo.Password=设置.Password;
//从报告中获取表信息
_crDatabase=\u crReportDocument.Database;
_crTables=\CRU DATABASE.Tables;
//循环浏览报告中的所有表并应用
//每个表的连接信息。
对于(int i=0;i<\u crTables.Count;i++)
{
_crTable=_crTables[i];
_crTableLogOnInfo=\u crTable.LogOnInfo;
_crTableLogOnInfo.ConnectionInfo=\u crConnectionInfo;
_crTable.ApplyLogOnInfo(_crTableLogOnInfo);
}

您可以尝试在页面卸载事件中使用此选项

Report.Close();
Report.Dispose();
当页面被卸载时,这应该会删除报告,当用户返回页面时,您将重新开始。
这篇文章中有一个很好的例子。

我找到了解决方案!!!!------不是

在我上面问题中的所有代码之前添加这一行:

 CrystalReportViewer1.ParameterFieldInfo.Clear();

然后加载文件名,依此类推……

很抱歉,在加载所有内容后会触发Page_Unload事件;因此,它将在可以查看报告之前关闭/处理该报告。我刚刚看到您添加到问题中的代码。你为什么要把第2行到第4行注释掉?这应该会解决问题->清除页面加载上的所有内容,然后加载报告。我注释掉的行不起作用,但我将它们留在那里,因此我不再重试。您是否尝试将我的答案中的代码放在页面加载事件的开头?您注释掉的三行代码也必须在Page_Load事件的最开始处执行,以便首先执行它们。好吧,我收回它。经过一些测试,上面的新行将阻止报告的打印。很奇怪。不过我会找到解决办法的。。。。