开发者

Crystal Reports: ParamerterValue dialog appears despite of the values are set programmatically

开发者 https://www.devze.com 2023-01-19 03:13 出处:网络
I am working with crystal report 2008 I have a Parameter Field named HeaderColumn1, whose value I want to pass programmatically.

I am working with crystal report 2008

I have a Parameter Field named HeaderColumn1, whose value I want to pass programmatically.

I set the parameter field value with following code:

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(开发者_开发技巧);

On running this code, it prompts for the ParameterValue of HeaderColumn1 parameter.

Why so ? Any solutions or suggestions ? Thanks a ton in advance.

:))


Solution:

It worked finally using following:

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();


Your Code didn't work for me I'm afraid, but this did (found elsewhere) and may be helpful to others -

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(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消