logo FastReport中文文档
文档首页>>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();
}

如果我们运行该报告,会得到以下结果:

扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP

欢迎来到慧都网!

请告诉我您的需求?

或留下您的联系方式

我们将尽快为您解答!

请您留言

欢迎来到慧都网,客服值守时间为:工作日9:00-12:00,13:00-17:30,或直接拨打:18166486035(微信同号)

提交