向 Web 或 Windows 窗体添加控件
在本节中,您要在 Web 或 Windows 窗体上的 CrystalReportViewer 控件上方添加 DropDownList、Button 和 Label 控件。
向 Web 或 Windows 窗体添加控件
打开 Web 或 Windows 窗体。
从“视图”菜单中,单击“设计器”。
如果在开发网站,则执行以下操作:
- 单击 CrystalReportViewer 控件,将其选中。
- 在键盘上按左箭头,待出现闪烁的光标后,按 Enter 键。
CrystalReportViewer 控件将下移一行。
如果在开发 Windows 项目,则执行以下操作:
1. 单击 CrystalReportViewer 控件,将其选中。
2. 在“属性”窗口中,将“Dock”设置为“Bottom”。
3. 调整“CrystalReportViewer”控件的大小,直到在其上方为“ComboBox”控件留出足够的空间。
4. 在“属性”窗口中,将“Anchor”设置为“Top, Bottom, Left, Right”。
- 从“工具箱”中将一个“DropDownList”控件(在网站中)或“ComboBox”控件(在 Windows 项目中)拖到“CrystalReportViewer”控件上方。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>当使用 Visual Studio 2005 或更高版本时,如果 DropDownList (ComboBox) 上出现“智能任务”,请按 Esc 键关闭它。</p></td>
</tr>
</tbody>
</table>
单击“DropDownList”(ComboBox) 控件选中它。
从“属性”窗口中,将“ID”属性设置为“exportTypesList”。
从“工具箱”中,将“Button”控件拖到“DropDownList”(ComboBox) 控件的右侧。
单击选中“Button”控件。
从“属性”窗口中执行以下操作:
- 将“ID”属性设置为“exportByType”。
- 将“Text”属性设置为“导出为选定类型”。
从“工具箱”中,将“Label”控件拖到“Button”控件的右侧。
单击选中“Label”控件。
从“属性”窗口中执行以下操作:
- 将“ID”属性设置为“message”。
- 将“Text”属性设置为空白。
- 将“Visible”属性设置为“False”。
从“文件”菜单中选择“全部保存”。
现在必须从 CrystalDecisions.Shared 命名空间的 ExportFormatType 枚举填充 DropDownList 控件。
为网站从 ExportFormatType 枚举填充 DropDownList 控件
打开 Web 窗体。
从“视图”菜单中,单击“代码”。
在 ConfigureCrystalReports() 方法中,在于该方法的底部,添加 Not IsPostBack 条件块。
``` vb
If Not IsPostBack Then
End If
```
``` csharp
if (!IsPostBack)
{
}
```
在该条件块中,将 exportTypesList ComboBox 控件的 DataSource 属性设置为 ExportFormatType 枚举的值。
exportTypesList.DataSource = System.Enum.GetValues(GetType(ExportFormatType))
exportTypesList.DataSource = System.Enum.GetValues(typeof(ExportFormatType));
调用 exportTypesList DropDownList 控件的 DataBind() 方法,将值绑定到控件。
``` vb
exportTypesList.DataBind()
```
``` csharp
exportTypesList.DataBind();
```
为 Windows 项目从 ExportFormatType 枚举填充 DropDownList 控件
打开 Windows 窗体。
从“视图”菜单中,单击“代码”。
在 ConfigureCrystalReports() 方法中,于该方法的底部,将 exportTypesList ComboBox 控件的 DataSource 属性设置为 ExportFormatType 枚举的值。
exportTypesList.DataSource = System.Enum.GetValues(GetType(ExportFormatType))
exportTypesList.DataSource = System.Enum.GetValues(typeof(ExportFormatType));