1. crystalreportviewer
Use the crystalreportviewer. parameterfieldinfo attribute ......
1. crystalreportviewer Member
Public instance attributes
Parameterfieldinfo (inherited from crystalreportviewerbase) parameterfields. Obtains or sets a set of parameter fields.
2. reportdocument
Use the reportdocument. datadefinition. parameterfields attribute ......
1. reportdocument Member
Public instance attributes
Datadefinition. Obtain the datadefinition object.
2. datadefinition Member
Public instance attributes
Parameterfields parameterfielddefinitions. Obtain the parameterfielddefinitions set.
Iii. Custom parameter field during running (crystalreportviewer)
Refer:
Set parameters | binding options for Windows form viewer | binding options for web form Viewer
You can enter parameters in the crystal report. This parameter has multiple purposes. For example:
The parameter is based on the database field and allows you to specify the value of this field to filter data in the report.
Use the parameter field to apply the condition format to the report.
Use parameter fields to define the sorting order.
The following example shows how to set the parameter field value in the code at runtime. This example explains how to set two different parameters: the first is a multi-value discrete parameter, and the second is a region value parameter.
Modify parameter fields during runtime
[Visual Basic]
'Declare to pass the parameter
'Variables required by the viewer control.
Dim paramfields as new parameterfields ()
Dim paramfield as new parameterfield ()
Dim discreteval as new parameterdiscretevalue ()
Dim rangeval as new parameterrangevalue ()
'The first parameter is a discrete parameter with multiple values.
'Set the parameter field name, which must
'Is consistent with the parameters in the report.
Paramfield. parameterfieldname = "customer name"
'Set the first discrete value and pass it to this parameter
Discreteval. value = "AIC childrens"
Paramfield. currentvalues. Add (discreteval)
'Set the second discrete value and pass it to this parameter.
The 'discreteval variable is set as a new value. In this way, the previous settings
'Will not be overwritten.
Discreteval = new parameterdiscretevalue ()
Discreteval. value = "Aruba sport"
Paramfield. currentvalues. Add (discreteval)
'Add this parameter to the parameter field set.
Paramfields. Add (paramfield)
'The second parameter is the region value. Paramfield variable
'Is set as the new value, so that the previous settings will not be overwritten.
Paramfield = new parameterfield ()
'Set the parameter field name, which must
'Is consistent with the parameters in the report.
Paramfield. parameterfieldname = "Customer ID"
'Set the start and end values of the region and pass the region to this parameter.
Rangeval. startvalue = 42
Rangeval. endvalue = 72
Paramfield. currentvalues. Add (rangeval)
'Add the second parameter to the parameter field set.
Paramfields. Add (paramfield)
'Place the set of parameter fields into the viewer control.
Crystalreportviewer1.parameterfieldinfo = paramfields
Crystalreportviewer1.reportsource = "C:/reports/my report. rpt"
[C #]
// Declare to pass the parameter
// Variables required by the viewer control.
Parameterfields paramfields = new parameterfields ();
Parameterfield paramfield = new parameterfield ();
Parameterdiscretevalue discreteval = new parameterdiscretevalue ();
Parameterrangevalue rangeval = new parameterrangevalue ();
// The first parameter is a discrete parameter with multiple values.
// Set the name of the parameter field, which must
// Match the parameters in the report.
Paramfield. parameterfieldname = "customer name ";
// Set the first discrete value and pass it to this parameter.
Discreteval. value = "AIC childrens ";
Paramfield. currentvalues. Add (discreteval );
// Set the second discrete value and pass it to this parameter.
// The discreteval variable is set as a new value. In this way, the previous settings
// It will not be overwritten.
Discreteval = new parameterdiscretevalue ();
Discreteval. value = "Aruba sport ";
Paramfield. currentvalues. Add (discreteval );
// Add this parameter to the parameter field set.
Paramfields. Add (paramfield );
// The second parameter is the region value. Paramfield variable
// Is set as the new value, so that the previous settings will not be overwritten.
Paramfield = new parameterfield ();
// Set the name of the parameter field, which must
// Match the parameters in the report.
Paramfield. parameterfieldname = "Customer ID ";
// Set the start value and end value of the range and pass the range
// This parameter.
Rangeval. startvalue = 42;
Rangeval. endvalue = 72;
Paramfield. currentvalues. Add (rangeval );
// Add the second parameter to the parameter field set.
Paramfields. Add (paramfield );
// Put the set of parameter fields into the viewer control.
Crystalreportviewer1.parameterfieldinfo = paramfields;
[C ++]
// Declare to pass the parameter
// Variables required by the viewer control.
Parameterfields * paramfields = new parameterfields ();
Parameterfield * paramfield = new parameterfield ();
Parameterdiscretevalue * discreteval = new parameterdiscretevalue ();
Parameterrangevalue * rangeval = new parameterrangevalue ();
// The first parameter is a discrete parameter with multiple values.
// Set the name of the parameter field, which must
// Match the parameters in the report.
Paramfield-> parameterfieldname = "customer name ";
// Set the first discrete value and pass it to this parameter.
String * val = "AIC childrens ";
Discreteval-> value = val;
Paramfield-> currentvalues-> Add (discreteval );
// Set the second discrete value and pass it to this parameter.
// The discreteval variable is set as a new value. In this way, the previous settings
// It will not be overwritten.
Discreteval = new parameterdiscretevalue ();
Val = "Aruba sport ";
Discreteval-> value = val;
Paramfield-> currentvalues-> Add (discreteval );
// Add this parameter to the parameter field set.
Paramfields-> Add (paramfield );
// The second parameter is the region value. Paramfield variable
// Is set as the new value, so that the previous settings will not be overwritten.
Paramfield = new parameterfield ();
// Set the name of the parameter field, which must
// Match the parameters in the report.
Paramfield-> parameterfieldname = "Customer ID ";
// Set the start value and end value of the range and pass the range
// This parameter.
Rangeval-> startvalue = _ box (42 );
Rangeval-> endvalue = _ box (72 );
Paramfield-> currentvalues-> Add (rangeval );
// Add the second parameter to the parameter field set.
Paramfields-> Add (paramfield );
// Put the set of parameter fields into the viewer control.
Crystalreportviewer1-> parameterfieldinfo = paramfields;
Crystalreportviewer1-> exportreport ();