我正在使用水晶报告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。
为什么这样?任何解决方案或建议?非常感谢。
:))
答案 0 :(得分: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();
答案 1 :(得分: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();