Share via


Adding Controls to the Web or Windows Form

In this section, you add a DropDownList, Button, and Label control above the CrystalReportViewer control on the Web or Windows Form.

To add controls to the Web or Windows Form

  1. Open the Web or Windows Form.

  2. From the View menu, click Designer.

  3. If you are developing a Web Site, do the following:

    1. Click the CrystalReportViewer control to select it.
    2. Press the LEFT ARROW on your keyboard so that a flashing cursor appears, and then press ENTER.

    The CrystalReportViewer control drops by one line.

  4. If you are developing a Windows project, do the following:

1.  Click the CrystalReportViewer control to select it.
2.  From the Properties window, set Dock to "Bottom."
3.  Resize the CrystalReportViewer control, so that you leave enough room above it for a ComboBox control.
4.  From the Properties window, set Anchor to "Top, Bottom, Left, Right."
  1. From the Toolbox, drag a DropDownList control (in Web Sites) or ComboBox control (in Windows projects) above the CrystalReportViewer control.
> [!NOTE]
> <P>If a Smart Task appears on the DropDownList (ComboBox) when you use Visual Studio 2005 or later, press Esc to close it.</P>
  1. Click the DropDownList (ComboBox) control to select it.

  2. From the Properties window, set the ID property to "exportTypesList."

  3. From the Toolbox, drag a Button control to the right of the DropDownList (ComboBox) control.

  4. Click the Button control to select it.

  5. From the Properties window, do the following:

    • Set the ID property to "exportByType."
    • Set the Text property to "Export As Selected Type."
  6. From the Toolbox, drag a Label control to the right of the Button control.

  7. Click the Label control to select it.

  8. From the Properties window, do the following:

    • Set the ID property to "message."
    • Set the Text property to be blank.
    • Set the Visible property to "False."
  9. From the File menu, select Save All.

Now you must populate the DropDownList control from the ExportFormatType enum of the CrystalDecisions.Shared namespace.

To populate the DropDownList control from the ExportFormatType enum for a Web Site

  1. Open the Web Form.

  2. From the View menu, click Code.

  3. Within the ConfigureCrystalReports() method, at the bottom of the method, add a Not IsPostBack conditional block.

``` vb
If Not IsPostBack Then

End If
```

``` csharp
if (!IsPostBack)
{
}
```
  1. Within the conditional block, set the DataSource property of the exportTypesList ComboBox control to the values of ExportFormatType enum.

    exportTypesList.DataSource = System.Enum.GetValues(GetType(ExportFormatType))
    
    exportTypesList.DataSource = System.Enum.GetValues(typeof(ExportFormatType));
    
  2. Call the DataBind() method of the exportTypesList DropDownList control to bind the values to the control.

``` vb
exportTypesList.DataBind()
```

``` csharp
exportTypesList.DataBind();
```

To populate the DropDownList control from the ExportFormatType enum for a Windows project

  1. Open the Windows Form.

  2. From the View menu, click Code.

  3. Within the ConfigureCrystalReports() method, at the bottom of the method, set the DataSource property of the exportTypesList ComboBox control to the values of the ExportFormatType enum.

    exportTypesList.DataSource = System.Enum.GetValues(GetType(ExportFormatType))
    
    exportTypesList.DataSource = System.Enum.GetValues(typeof(ExportFormatType));