Passing parameters to crystal reports

xiaoxiao2021-03-06  112

Reference - http://imar.spaanjaars.com/quickdocid.aspx? QuickDoc = 310HTTP: //www.cddotnet.com/bbs/dispbbs.asp? BoardId = 3 & id = 3 & star = 1 # 4Http: //community.9cbs .net / Expert / topic / 3512 / 3512093.xml? temp = .3724787 ...... how to pass parameters to a CrystalReportViewer and ReportDocument, CrystalReportViewer by CrystalReportViewer.ParameterFieldInfo property ...... 1, CrystalReportViewer members of the public instance property ParameterFieldInfo (inherited from CrystalReportViewerbase) ParameterFields . Get or set the parameter field collection. Second, ReportDocument passes the ReportDocument.DataDefinition.Parameterfields property ... 1. ReportDocument member public instance attribute DATADEFINITION DATADEFINITION. Get the DATADEFINITION object. 2, DATADEFINITION Members Public Example Attribute Parameterfields ParameterfieldDefinitions. Get the ParameterfieldDefinitions collection. Third, the CrystalReportViewer "Reference: Setting Parameters | Network Options for Windows Forms | Bindings for Web Forms Viewer

The user can be supported by the parameter in the Crystal report. This parameter has a variety of uses. For example, the parameters are based on the database field and allow the user to specify the value of the field to filter data in the report. Use the parameter field to apply the condition format to the report. Use the parameter field to define the sort order. The following example shows how to set the parameter field value through the code at runtime. This example explains how to set two different parameters: the first is a multi-value discrete parameter, the second is the area value parameter.

Modify the parameter field at runtime

[C #] // The declaration passes the parameters to the variable required for 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 having a plurality of values.

/ / Set the name of the parameter field, it must / / and match the parameters in the report. PARAMFIELD.PARAMELDNAME = "Customer Name";

/ / Set the first discrete value and pass it to this parameter. Discreteval.Value = "AIC Childrens"; paramfield.currentVales.Add (Discreteval);

/ / Set the second discrete value and pass it to this parameter. // Discreteval variable is set to a new value, so that previous settings // will not be overwritten. Discreteval = new parameterdiscretevalue (); discreteval.value = "aruba sport"; paramfield.currentvalues.add (discreteval);

// Add this parameter to the parameter field collection. Paramfields.Add (paramfield);

// The second parameter is the zone value. PARAMFIELD variable // is set to a new value, so that the previous settings will not be overwritten. Paramfield = new parameterfield ();

/ / Set the name of the parameter field, it must / / and match the parameters in the report. PARAMFIELD.PARAMELDNAME = "Customer ID";

// Set the start value and end value of the range and pass the range to // this parameter. Rangeval.StartValue = 42; RangeVal.endValue = 72; paramfield.currentVales.add (Rangeval);

// Add the second parameter to the parameter field collection. Paramfields.Add (paramfield);

// Place the parameter field into the viewer control. CrystalReportViewer1.ParameterfieldInfo = paramfields; Crystal Report Version 9.2, the background is SQL Server 2000, the report data source is a stored procedure result with two parameters. No matter what parameters I have, the results of the report are the results of the crystal report development environment. Parameters I haven't passed it in. Please brothers help us to see where the problem is below the code using system; use system.componentmodel; use means system.data; useing system.drawing; useing system.Web; use system.Web .SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace erpreports {///

/ . // Summary description for WebForm1 /// public class WebForm1: System.Web.UI.Page {protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; mrb_pnper rpt; ParameterFields crParameterFields; ParameterField crParameterField; ParameterValues ​​crParameterValues; ParameterDiscreteValue crParameterDiscreteValue;

Private void page_load (object sender, system.eventargs e) {// put user code to initialize the page here}

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {/// Codegen: This Call is Required by the ASP.NET Web Form Designer. // InitializeComponent (); Base.onit (E); RPT = New MRB_PnPER (); CrystalReportViewer1.Reportsource = RPT;

// Get the collection of parameters from the report crParameterFields = CrystalReportViewer1.ParameterFieldInfo; crParameterField = crParameterFields [ "@ begindate"]; crParameterValues ​​= crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue (); crParameterDiscreteValue.Value = Request.QueryString [ "begindate" ]; CrParameterValues.Add (CRPARETERDISCRETEVALUE);

crParameterField = crParameterFields [ "@ enddate"]; crParameterValues ​​= crParameterField.CurrentValues; crParameterDiscreteValue = new ParameterDiscreteValue (); crParameterDiscreteValue.Value = Request.QueryString [ "enddate"]; crParameterValues.Add (crParameterDiscreteValue); CrystalReportViewer1.ParameterFieldInfo = crParameterFields;

} ///

/// Required Method for Designer Support - Do Not Modify ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////>> New system.eventhandler (this.page_load);

} #Endregion}}}

转载请注明原文地址:https://www.9cbs.com/read-97418.html

New Post(0)