简体   繁体   English

如何传递和使用自定义类到RDLC报告?

[英]How do I Pass and use a Custom Class to an RDLC report?

So I have a class called CustomClass1 which has several string and DateTime properties. 因此,我有一个名为CustomClass1的类,它具有多个字符串和DateTime属性。 I'm passing an instance of another class to an RDLC that has, amongst other things, several properties of type CustomClass1. 我正在将另一个类的实例传递给RDLC,该RDLC除其他外,还具有几个CustomClass1类型的属性。

in the RDLC I am configuring the Dataset field as below: 在RDLC中,我正在如下配置“数据集”字段:

   <DataSet Name="ExtensionRequestFormViewerModel">
     <Fields>
       <Field Name="SomeField">
         <DataField>SomeField</DataField>
         <rd:TypeName>FullyQualifiedNameSpace.CustomClass1</rd:TypeName>
       </Field>
       --- Other Fields
     </Fields>
   </DataSet>

I can see the property is populated in the data being sent to the RDLC, but when I try to read the data as below: 我可以看到该属性填充在发送到RDLC的数据中,但是当我尝试按以下方式读取数据时:

<Value>=Fields!SomeField.Value.Property1</Value>

I get an #Error in the FormViewer 我在FormViewer中收到#Error

is there a specific way of registering and handling custom classes in RDLC reports? 有没有在RDLC报告中注册和处理自定义类的特定方法?

Thanks 谢谢

Stewart 斯图尔特

No responses, but I worked it out. 没有回应,但我解决了。 If I made the CustomClass1 class serializable the RDLC was able to deal with the class. 如果我使CustomClass1类可序列化,则RDLC可以处理该类。

Say I have a custom class that holds some data like this: 假设我有一个自定义类,其中包含一些数据,如下所示:

[Serializable]
public class AppTelecommunicationsNumber : AppContactMechanism {
    public int AreaCode { get; set; }
    public string ContactNumber { get; set; }
    public int? CountryCode { get; set; }
    public string Extention { get; set; }
}

Say I want to display the ContactNumber field on a report. 假设我要在报表上显示ContactNumber字段。 You must add the [Serializable] attribute to your class before you can reference it in the expression editor in the RDLC designer. 必须在类中添加[Serializable]属性,然后才能在RDLC设计器的表达式编辑器中对其进行引用。

You can then reference the fieldname directly like this: 然后,您可以像这样直接引用字段名称:

=First(Fields!PhoneNumber.Value.ContactNumber, "WorkOrderViewModel")

FWIW: I had written hundreds of reports before I figured this out. FWIW:在弄清楚之前,我已经写了数百份报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM