将 rdlc 报告与业务对象绑定

发布于 2024-09-29 01:40:24 字数 162 浏览 0 评论 0原文

是否可以将 rdlc 报告绑定到业务对象(.NET 4/VS 2010)

在我的报告中,我有名为“名称”和“电子邮件”的文本框。

假设我有一个具有 Name 和 Email 属性的对象 Person。

我可以在运行时将 .rdlc 与对象 Person 绑定吗?

Is it possible to bind a rdlc report to a business object (.NET 4/VS 2010)

In my report I have TextBoxes called Name and Email.

Say I have an object Person with properties Name and Email.

Can I bind the .rdlc with an object Person at runtime?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抽个烟儿 2024-10-06 01:40:24

是的,只需创建一个新的 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 };

可能有更好的方法来获取对象属性,但我还没找到。

Yes it is, just create a new 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);

If you object has collection properties you can flatten the data before you send it to the report, then use grouping to show the hierarchy:

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 };

There might be a better way to get at the object properties, but I haven't found it yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文