【问题标题】:Rdlc: reporting off a child object that is an IList of some primitive typeRdlc:报告作为某种原始类型列表的子对象
【发布时间】:2010-06-29 16:03:21
【问题描述】:

我正在使用 rdlc 报告来报告一些业务对象。 我使用子报表来报告嵌套对象(如here 所述)。

当使用常规的子对象列表时,例如 IList(Of Books),我会为书籍创建一个数据源,然后将其用作子报表的数据源。

当嵌套对象是 IList(Of String) 或其他基本类型的列表时,我不知道如何使用此技术。

在这种情况下进行报告的最佳方式是什么?

【问题讨论】:

    标签: rdlc


    【解决方案1】:

    我遇到了类似的问题。我有一个运行自定义对象列表的报告。 CustomObject 列表是从对包含对其所有 CustomObjects 的许多引用的 ParentObjects 列表的查询中填充的。该关系已被删除,而是在 ParentObject (ParentObject.CustomObjectName) 上使用了一个字符串列。现在我的报告收到一个包含所有 CustomObject 名称的字符串 []。

    我的解决方案是使用单个字符串属性和构造函数创建一个包装器对象,以用作我的数据源。我将它命名为我的报告所期望的 CustomObject。

    class CustomObject 
    { 
       public string Name {get; set;} 
    
       public CustomObject(string name)
       {
          Name = name;
       }
    }
    

    我使用 LINQ 加载我的列表,我在 select 语句中调用包装构造函数

    var wrappedObjects = from parent in GetParentObjects()
       select new CustomObject(parent.CustomObjectName);
    

    从报告中,您可以像往常一样为 CustomObject 类添加数据源,并像往常一样访问对象“=Fields!Name.Value”。

    【讨论】:

      【解决方案2】:

      我有一个像这样的对象结构

      Order -> List:OrderItems(Products) -> List:AdditionalProducts(Products)

      我有一个带有子报表和子子报表的主报表。

      我通过以下方式解决了这个问题

      在子报表中,我将参数传递给子报表。此参数有一个产品名称的值,称为“thisproduct”。

      子报表和子子报表都调用子报表处理函数。 所以我需要在这里为两者分配数据源。

      1. 我为子报表(order.items)分配数据源

      2. 如果子子报表 (InternalOrderItemAdditionalProducts) 正在调用此函数,我会添加一个“if”。在这里我检查参数,并获取产品名称。然后我可以遍历订单项,找到与正在查看的产品相关的订单项,然后将子子报表数据源分配为与该产品相关的附加产品。

         private void SubreportProcessing(object sender, SubreportProcessingEventArgs e)
          {     
          // assign subreport datasource
          e.DataSources.Add(new ReportDataSource("OrderItems", order.Items));
        
          // if the subsubreport is calling this then
          if (e.ReportPath != null)
              if (e.ReportPath == "InternalOrderItemAdditionalProducts")
              {
                  // find the orderitem relating to this product
                  foreach (var orderitem in order.Items)
                  {
                      if (e.Parameters["thisproduct"].Values[0] == orderitem.ProductType.Name)
                      {
                          // assign the subsubreport datasource to be the additional products of that order item
                          e.DataSources.Add(new ReportDataSource("AdditionalProducts",
                                                                 orderitem.Product.AllDescendentAdditionalProducts));
                      }
                  }
              }
        

        }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多