使用自定义数据创建 Activereports PageReport
Activereports PageReport creation by using custom data
我想根据我的自定义 class 创建一个页面报告,我的 PageReport 中包含一个 table。
例如我有一个客户数据class如下
Class CustomerData
{
string name;
string id;
string address;
}
然后我创建了一个 List<CustomerData>
CustomerList,其中包含我所有的客户数据。我想将此数据指定为我的 Pagereport 的数据源。我知道在 SectionReport 中我们可以这样做。但是如何将我的信息列表分配给PageReport。谁能帮帮我
最终我希望得到如下所示的输出
----------------------------------------------
|Name | ID | Address |
----------------------------------------------
|Name1 | ID1 | Address1 |
----------------------------------------------
|Name2 | ID2 | Address2 |
----------------------------------------------
|Name3 | ID3 | Address3 |
----------------------------------------------
更新
ComponentIdInfo 是字段之一
做,像这样:
this._rptPath = new FileInfo(@"..\..\PageReport1.rdlx");
this._definition = new PageReport(this._rptPath);
this._definition.ConfigurationProvider = new GrapeCity.ActiveReports.Configuration.DefaultConfigurationProvider();
this._runtime = new PageDocument(this._definition);
this._runtime.LocateDataSource += this.runtime_LocateDataSource;
this.YourViewer.ReportViewer.LoadDocument(this._runtime);
在您的 runtime_LocateDataSource
活动中,添加以下代码:
private void runtime_LocateDataSource(object sender, LocateDataSourceEventArgs args)
{
object data = null;
string dataSetName = args.DataSetName;
string dataSourceName = args.DataSourceName;
if (StringsAreEqual("DataSource1", dataSourceName))
{
if (StringsAreEqual("DataSet1", dataSetName))
{
data = CustomerListDataTable;
}
}
args.Data = data;
}
private static bool StringsAreEqual(string str1, string str2)
{
return string.Compare(str1, str2, true, CultureInfo.InvariantCulture) == 0;
}
请注意,您必须在页面报告中创建名为 DataSource1
的 DataSource
和名为 DataSet1
的 DataSet
。并将DataSet1
的列名匹配到Customer's
classpublic properties
.
要到达 Add DataSource
,请右键单击 page report
(灰色区域)和 select property
之外的位置,然后寻找 DataSource
在 property
window.
如何添加DataSource/DataSet
- 在报表资源管理器中,右键单击“数据源”节点并select“添加数据源”选项。
- 在出现的“报表数据源”对话框中,select“常规”页面和“名称”字段中,输入一个名称,例如 DataSource1。
- 右键单击数据源节点和 select 添加数据集选项。
- 在出现的“数据集”对话框中,select“常规”页面并输入数据集名称作为 DataSet1。此名称在报表资源管理器中显示为数据源图标的子节点。
- 转到字段选项卡并在那里输入您的数据集的字段(列)
请注意,如果找不到 Report Explorer
,请转到 Visual Studios
View
菜单并转到 Other Windows
。
您要实现的目标可以在 RDL/Page 报告中使用对象数据提供程序来实现。请检查此 link 以获取详细信息和代码示例。请注意 "Unbound Data Source" 部分下的对象提供者主题。
我想根据我的自定义 class 创建一个页面报告,我的 PageReport 中包含一个 table。
例如我有一个客户数据class如下
Class CustomerData
{
string name;
string id;
string address;
}
然后我创建了一个 List<CustomerData>
CustomerList,其中包含我所有的客户数据。我想将此数据指定为我的 Pagereport 的数据源。我知道在 SectionReport 中我们可以这样做。但是如何将我的信息列表分配给PageReport。谁能帮帮我
最终我希望得到如下所示的输出
----------------------------------------------
|Name | ID | Address |
----------------------------------------------
|Name1 | ID1 | Address1 |
----------------------------------------------
|Name2 | ID2 | Address2 |
----------------------------------------------
|Name3 | ID3 | Address3 |
----------------------------------------------
更新
ComponentIdInfo 是字段之一
做,像这样:
this._rptPath = new FileInfo(@"..\..\PageReport1.rdlx");
this._definition = new PageReport(this._rptPath);
this._definition.ConfigurationProvider = new GrapeCity.ActiveReports.Configuration.DefaultConfigurationProvider();
this._runtime = new PageDocument(this._definition);
this._runtime.LocateDataSource += this.runtime_LocateDataSource;
this.YourViewer.ReportViewer.LoadDocument(this._runtime);
在您的 runtime_LocateDataSource
活动中,添加以下代码:
private void runtime_LocateDataSource(object sender, LocateDataSourceEventArgs args)
{
object data = null;
string dataSetName = args.DataSetName;
string dataSourceName = args.DataSourceName;
if (StringsAreEqual("DataSource1", dataSourceName))
{
if (StringsAreEqual("DataSet1", dataSetName))
{
data = CustomerListDataTable;
}
}
args.Data = data;
}
private static bool StringsAreEqual(string str1, string str2)
{
return string.Compare(str1, str2, true, CultureInfo.InvariantCulture) == 0;
}
请注意,您必须在页面报告中创建名为 DataSource1
的 DataSource
和名为 DataSet1
的 DataSet
。并将DataSet1
的列名匹配到Customer's
classpublic properties
.
要到达 Add DataSource
,请右键单击 page report
(灰色区域)和 select property
之外的位置,然后寻找 DataSource
在 property
window.
如何添加DataSource/DataSet
- 在报表资源管理器中,右键单击“数据源”节点并select“添加数据源”选项。
- 在出现的“报表数据源”对话框中,select“常规”页面和“名称”字段中,输入一个名称,例如 DataSource1。
- 右键单击数据源节点和 select 添加数据集选项。
- 在出现的“数据集”对话框中,select“常规”页面并输入数据集名称作为 DataSet1。此名称在报表资源管理器中显示为数据源图标的子节点。
- 转到字段选项卡并在那里输入您的数据集的字段(列)
请注意,如果找不到 Report Explorer
,请转到 Visual Studios
View
菜单并转到 Other Windows
。
您要实现的目标可以在 RDL/Page 报告中使用对象数据提供程序来实现。请检查此 link 以获取详细信息和代码示例。请注意 "Unbound Data Source" 部分下的对象提供者主题。