【发布时间】:2010-10-26 22:30:27
【问题描述】:
是否可以将 rdlc 报告绑定到业务对象(.NET 4/VS 2010)
在我的报告中,我有名为名称和电子邮件的文本框。
假设我有一个对象 Person,其属性为 Name 和 Email。
我可以在运行时将 .rdlc 与对象 Person 绑定吗?
【问题讨论】:
标签: c# .net asp.net reporting rdlc
是否可以将 rdlc 报告绑定到业务对象(.NET 4/VS 2010)
在我的报告中,我有名为名称和电子邮件的文本框。
假设我有一个对象 Person,其属性为 Name 和 Email。
我可以在运行时将 .rdlc 与对象 Person 绑定吗?
【问题讨论】:
标签: c# .net asp.net reporting rdlc
是的,只需创建一个新的 ReportDataSource:
var people = new List<Person>();
var reportDataSource = new Microsoft.Reporting.WebForms.ReportDataSource {Name = "DataSet1", Value = people};
var report = new Microsoft.Reporting.WebForms.LocalReport();
report.DataSources.Add(reportDataSource);
如果您的对象具有集合属性,您可以在将数据发送到报表之前展平数据,然后使用分组来显示层次结构:
var myEvent = new Event("Test Name", "Test Location", new List<Person>());
var reportData = myEvent.Persons.Select(p => new { myEvent.EventName, myEvent.EventLocation, p.Name, p.Email });
var reportDataSource = new Microsoft.Reporting.WebForms.ReportDataSource { Name = "DataSet1", Value = reportData };
可能有更好的方法来获取对象属性,但我还没有找到。
【讨论】: