RDLC对象数据源中的嵌套列表 [英] Nested List in RDLC Object DataSource

查看:146
本文介绍了RDLC对象数据源中的嵌套列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有以下课程:

Hi everyone,

I have the following class:

public class Test
{
    public string Name {get;set;}
    public List<string> stringitems {get;set;}
    public List<subclass> subclassitems {get;set;}
}

public class SubClass
{
  public string Value {get;set;};
}
</subclass></string>



我想将此作为RDLC报告中的数据源传递.

我怎么可能知道您是否有嵌套类型,例如= Fields!SubClass.Value.Value

但是我不知道清单.并且List< string>似乎也有一些问题.类型.



And I want to pass this as a datasource in a RDLC report.

How is this possible I know if you have a nested type you do like this for example =Fields!SubClass.Value.Value

But i dont know about lists. And also there seems to be some problem with a List<string> type.

can anyone please help thx appreciate it.

推荐答案

如果您为列表项创建子报表并将其包含在主报表中,则可以完成此操作.

然后处理SubreportProcessing事件并设置子报表的数据源.下面的示例代码.

You can accomplish this if you create a sub report for the list items and include it in your main report.

Then handle the SubreportProcessing event and set the datasource for the subreport. Sample code below.

ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);





public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
{
    var mainSource = ((LocalReport) sender).DataSources["DataSet1"];
    var subSource = ((List<test>)mainSource.Value).First().subclassitems;
    e.DataSources.Add(new ReportDataSource("SubDataSet1", subSource));
}


我创建了一个方法,使用反射来查找属性,在​​rdlc中调用该方法并获取值...
i create a method, using reflection to find property, in rdlc call the method and get the value...


这篇关于RDLC对象数据源中的嵌套列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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