文档半岛外围网上直营>>FastReport中文文档>>示例 6.使用数据源
示例 6.使用数据源
在所有示例中,我们都打印了一个包含普通文本的表格。在本示例中,我们将演示如何使用数据源创建表格。为此,我们将创建一个格式如下的表格:
我们将创建 ManualBuild 事件处理程序,它将执行以下操作:
- 获取报告中定义的数据源。
- 初始化(填充数据)。
- 打印表格行数,打印次数与数据源中的行数相同。
以下是处理程序的代码:
private void Table1_ManualBuild(object sender, EventArgs e)
{
// get the data source by its name
DataSourceBase rowData = Report.GetDataSource("Products");
// initialize it
rowData.Init();
// printing the table header
Table1.PrintRow(0);
Table1.PrintColumns();
// loop through the data source rows
while (rowData.HasMoreRows)
{
// printing the table row
Table1.PrintRow(1);
Table1.PrintColumns();
// select the next data row
rowData.Next();
}
// printing the table footer
Table1.PrintRow(2);
Table1.PrintColumns();
}
如果我们运行该报告,会得到以下结果:

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线