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...