2

我正在使用水晶报告 2008

我有一个名为 HeaderColumn1 的参数字段,我想以编程方式传递其值。

我使用以下代码设置参数字段值:

ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields;
ParameterField paramField;
ParameterDiscreteValue paramDiscreteValue;

paramField = new ParameterField();
paramField.Name = "HeaderColumn1";
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "Customer Code";
paramField.CurrentValues.Add(paramDiscreteValue);


paramFields.Add(paramField);

crystalReportViewer1.ReportSource = reportDocument;
crystalReportViewer1.ParameterFieldInfo = paramFields;
crystalReportViewer1.RefreshReport();

在运行此代码时,它会提示输入 HeaderColumn1 参数的 ParameterValue。

为什么这样 ?任何解决方案或建议?提前致谢。

:))

4

2 回答 2

0

解决方案:

它最终使用以下方法工作:

ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields;
ParameterField paramField;
ParameterDiscreteValue paramDiscreteValue;


paramField = crystalreportviewer1.ParameterFieldInfo["HeaderColumn1"];
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "Customer Code";
paramField.CurrentValues.Add(paramDiscreteValue);


paramFields.Add(paramField);


crystalReportViewer1.ReportSource = reportDocument;
crystalReportViewer1.ParameterFieldInfo = paramFields;
crystalReportViewer1.RefreshReport();
于 2010-10-15T05:45:13.457 回答
0

恐怕您的代码对我不起作用,但这确实(在其他地方找到)并且可能对其他人有所帮助-

ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

ParameterFieldDefinitions crParameterFieldDefinitions ;
ParameterFieldDefinition crParameterFieldDefinition ;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = Convert.ToInt32(textBox1.Text);
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["Price"];
crParameterValues = crParameterFieldDefinition.CurrentValues;

crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh(); 
于 2013-06-07T11:36:08.900 回答