ASP.NET - how to get value from aspx page to print in crystal report in

Asked By mani on 22-Dec-11 02:54 AM
hi..i have some value in aspx page..and when i click report button i need to send some values from aspx to crystall report..
any help??
dipa ahuja replied to mani on 22-Dec-11 03:01 AM
For this you have to create the crystal report with parameters:
► Select the Field Explorer from CrystalReport Menu.
► Then you can see Field Explorer in the Left hand side.
► Select Parameter Field from Field Explorer and right Click on Parameter Field.
► Fill the appropriate name for Name and Prompting text fields
► After creating the parameter field , we have to create the selection formula for the Crystal Reports parameter.
Full artcle :
kalpana aparnathi replied to mani on 22-Dec-11 03:03 AM
Try this code:

Page_load(., ., ., .);
if ((Session("report1") == null)) {
  CrystalReportViewer1.ParameterFieldInfo = myParameterFields;
  report1 = new ReportDocument();
  reportPath = Server.MapPath("CrystalReport1.rpt");
  Session("report1") = report1;
else {
  report1 = ((ReportDocument)(Session("report1")));
CrystalReportViewer1 = report1;
CrystalReportViewer1.DisplayToolbar = true;
CrystalReportViewer1.HasPrintButton = true;
CrystalReportViewer1.DisplayGroupTree = true;
CrystalReportViewer1.HasCrystalLogo = false;
Riley K replied to mani on 22-Dec-11 03:43 AM

Do you mean you want to print crystal report

//Get the Copy times
    int nCopy = this.printDocument1.PrinterSettings.Copies;
    //Get the number of Start Page
    int sPage = this.printDocument1.PrinterSettings.FromPage;
    //Get the number of End Page
    int ePage = this.printDocument1.PrinterSettings.ToPage;
    //Get the printer name
    string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
    crReportDocument = new ReportDocument();
    //Create an instance of a report
    crReportDocument = new Chart();
      //Set the printer name to print the report to. By default the sample
      //report does not have a defult printer specified. This will tell the
      //engine to use the specified printer to print the report. Print out
      //a test page (from Printer properties) to get the correct value.
      crReportDocument.PrintOptions.PrinterName = PrinterName;
      //Start the printing process. Provide details of the print job
      //using the arguments.
      crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);
      //Let the user know that the print job is completed
      MessageBox.Show("Report finished printing!");
    catch(Exception err)

Jitendra Faye replied to mani on 22-Dec-11 03:52 AM
You can pass value using parameters.

like this

ReportDocument report = new ReportDocument();


report.FileName = Server.MapPath(@"~/reports/rptCustomerRecords.rpt");

report.SetParameterValue("@Userid", userid); // @UserId is the parameter you added at the design of the crystalReport and userid is the value for the parameters

CrystalReportViewer1.ReportSource = report;

Try this and let me know.

Anoop S replied to mani on 22-Dec-11 05:15 AM

Passing a parameter to a Crystal Report is easy; all you need to do is drop a ready-made parameter field from the Field Explorer to your report and when the report is loaded, the user is asked for the parameter's value automatically.

Passing multiple parameter values to a report programmatically is a bit trickier.

First, you have to use the correct parameter type. In the Field Explorer, add a new parameter and make sure that Allow multiple values and Discrete value(s) are selected. Next, drag the parameter from the Field Explorer on your report. Then open the Select Expert (right-click your report and choose Report | Select Expert...), double-click the field you're setting the parameter for (Country in this example), choose is equal to from the first drop-down, choose your parameter (?Country) from the second drop-down and click OK.

The next step is to add the code that passes the values for the parameters at run-time. The example below uses hard-coded values for a parameter that filters the report based on the country name, but in reality you can substitute these hard-coded values with any values you like. For example, you can retrieve them from a database, a user preference stored in the registry, or retrieve them from text boxes placed on a Windows form. Just make sure that the ParameterFieldName matches the name of the parameter in the Field Explorer (minus the question mark). Don't forget to import the CrystalDecisions.Shared  namespace.

Add the following code to the click handler of a button, the load handler of a form, or any other method that is applicable in your situation:

using CrystalDecisions.Shared;
private void ParamButton_Click(object sender, System.EventArgs e)
  // Create parameter objects
  ParameterFields myParams = new ParameterFields();
  ParameterField myParam = new ParameterField();
  ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();

  // Set the ParameterFieldName to the name of the parameter
  // created in the Field Explorer
  myParam.ParameterFieldName = "Country";
  // Add first country
  myDiscreteValue.Value = "USA";
  // Reuse myDiscreteValue, and assign second country
  myDiscreteValue = new ParameterDiscreteValue();
  myDiscreteValue.Value = "Netherlands";
  // Add param object to params collection
  // Assign the params collection to the report viewer
  myCrystalReportViewer.ParameterFieldInfo = myParams;
  // Assign the Report to the report viewer.
  // This method uses a strongly typed report,
  // but other methods are possible as well.
  myCrystalReportViewer.ReportSource = MyReportObject;

Assigning the ParameterFields object to the ParameterFieldInfo of the CrystalReportViewer object programmatically will also suppress the default dialog asking for parameters that normally appears when you open a report with parameters.