将参数从 Web 表单传递到 Crystal 报表
我有一份报告,我想将其显示在网络表单上。没有参数的报告运行良好。带参数的报告让我很头疼。这是我在 BindReport 方法中编写的代码,该代码在表单的页面加载事件上调用。
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("rptPositionwiseMontwiseActualSale.rpt"));
rpt.FileName = Server.MapPath("rptPositionwiseMontwiseActualSale.rpt");
rpt.SetParameterValue("CompanyName", "Cirin Pharmaceutical Pvt. Limited".ToString());
rpt.SetParameterValue("ReportTitle", "PositionWise MonthWise Sales".ToString());
rpt.SetParameterValue("parameters", "Year:2011".ToString());
//CrystalReportViewer1.ParameterFieldInfo = paramFields;
DataSet ds = getReportData();
rpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
//CrystalReportViewer1.RefreshReport();
我尝试了各种方法,例如将 ParameterFieldInfo 分配给报表查看器控件,但它在页面加载时显示提示,要求提供报表的参数值。我正在使用.NET 4.0。
编辑
我正在使用 Crystal Reports 的推送模型。它是否改变了我们从 asp.net 传递参数以进行报告的方式?
I have a report and I want to display it on a webform. Reports without parameters are working well. Reports with parameters are creating headache for me. This is the code I have written in BindReport method, which is called on page load event of the form.
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("rptPositionwiseMontwiseActualSale.rpt"));
rpt.FileName = Server.MapPath("rptPositionwiseMontwiseActualSale.rpt");
rpt.SetParameterValue("CompanyName", "Cirin Pharmaceutical Pvt. Limited".ToString());
rpt.SetParameterValue("ReportTitle", "PositionWise MonthWise Sales".ToString());
rpt.SetParameterValue("parameters", "Year:2011".ToString());
//CrystalReportViewer1.ParameterFieldInfo = paramFields;
DataSet ds = getReportData();
rpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
//CrystalReportViewer1.RefreshReport();
I have tried variety of things like assigning ParameterFieldInfo to reportviewer control, but it shows me prompt on page load asking for parameter values of the report. I'm using .NET 4.0.
Edit
I'm using push model for Crystal Reports. Does it change the way we can pass parameters to report from asp.net?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在运行时为 ASP.NET 设置参数值时,我认为您需要做更多的工作,而不仅仅是调用
SetParameterValue
这可能有点矫枉过正,但它确实有效,无论如何对我来说都很好。您必须确保参数名称完全匹配。
When setting Parameter values at runtime for ASP.NET I think you need to do a bit more work than just called
SetParameterValue
This is probably a bit of overkill but it does actually work, well for me anyway. You must ensure that the parameter names match exactly.
这是我在项目中使用的代码来查看水晶报告(它是一个Web控件)
要在代码中使用它:
主要要查看的方法是用户控件中的AddDiscreteValue和SetParameters
编辑:
抽象的相关方法:
Here is the code Im using in a project to view crystal reports (its a web control)
To use this in code:
The main methods to look at are AddDiscreteValue and SetParameters in the User Control
EDIT:
Abstracted relevant methods:
就这样用吧。
Use like that.