绑定一个业务对象的RDLC报告 [英] Binding an rdlc report with a business object

查看:198
本文介绍了绑定一个业务对象的RDLC报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能一个RDLC报告绑定到业务对象(.NET 4 / VS 2010)

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.

我可以绑定.rdlc在运行时使用的对象的人吗?

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

推荐答案

其实很容易,只要创建一个新ReportDataSource:

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.

这篇关于绑定一个业务对象的RDLC报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆