Share via


To create the click event method for the Button in a Web project

In this section you configure the display Button control to display the report selected from the reportsList control. Within the event method for this button, you rebind the CrystalReportViewer control to the selected report.

  1. Open the Web form.

  2. From the View menu, click Designer.

  3. Double-click the display Button control.

You are taken to the code-behind class where a display\_Click() event method has been automatically generated.

You are now ready to create the helper method that binds the value of reportsList to the crystalReportViewer control.
  1. Within the display_Click() event method that has just been auto-generated, instantiate a new ReportDocument.
``` vb
myReportDocument = New ReportDocument
```

``` csharp
reportDocument = new ReportDocument();
```
  1. Call the Load() method of the ReportDocument instance and pass it the value selected from reportsList.
``` vb
myReportDocument.Load(reportsList.SelectedValue)
```

``` csharp
reportDocument.Load(reportsList.SelectedValue);
```
  1. Assign the report into Session, using the report variable name as the Session identifier string.

    Session("myReportDocument") = myReportDocument
    
    Session["reportDocument"] = reportDocument;
    
  2. Rebind the report instance to the ReportSource property of the CrystalReportViewer control.

    myCrystalReportViewer.ReportSource = myReportDocument
    
    crystalReportViewer.ReportSource = reportDocument;
    
  3. From the Build menu, select Build Solution. If you have any build errors, go ahead and fix them now.

You are now ready to test your application. From the Debug menu, click Start. When the web form loads, select a report from the DropDownList control. The selected report should display correctly.