问题描述
我有一份报告,我想在网络表单上显示它.没有参数的报告工作得很好.带有参数的报告让我很头疼.这是我在 BindReport 方法中编写的代码,在表单的页面加载事件中调用.
i have a report and i want to display it on a webform. Reports without parameters are working nice and fine. 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();
我尝试了各种方法,例如将 ParameterFieldInfo 分配给 reportviewer 控件,但是它在页面加载时提示我询问报表的参数值.我正在使用 .NET 4.0
编辑 我正在使用推送模型来处理水晶报表.它是否改变了我们传递参数以从 asp.net 报告的方式
谢谢
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
thanks
推荐答案
在运行时为 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
string rptTitle = "This is Report Title";
rpt.SetParameterValue("ReportTitle", rptTitle);
ParameterDiscreteValue val = new ParameterDiscreteValue();
val.Value = rptTitle;
ParameterValues paramVals = new ParameterValues();
paramVals.Add(val);
rpt.ParameterFields["ReportTitle"].CurrentValues = paramVals;
rpt.DataDefinition.ParameterFields[0].ApplyCurrentValues(paramVals);
这可能有点矫枉过正,但它确实有效,无论如何对我来说都很好.您必须确保参数名称完全匹配.
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.
这篇关于从网络表单将参数传递给 Crystal 报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!