从网络表单将参数传递给 Crystal 报表

passing parameters to Crystal report from webforms(从网络表单将参数传递给 Crystal 报表)
本文介绍了从网络表单将参数传递给 Crystal 报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份报告,我想在网络表单上显示它.没有参数的报告工作得很好.带有参数的报告让我很头疼.这是我在 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 报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)