开发者

child objects in rdlc (Studio 2010RC)

I am attempting to reference a sub-object in a field expression in a studio 2010 report. This used to work in prior versions. When account references another object with properties the following used to work.

开发者_如何学Python=Fields!Account.Value.Name

(Name is a property of the child object, Account is the parent object)

The same expression syntax no longer works. How do I reference the properties of a sub-object in reporting services in an rdlc in studio 2010.

Thanks


I can confirm that this bug has been fixed in VS2010 SP1 ... but you have to mark all of the relevant classes as Serializable.

You can find a sample project on this site which shows a working version: http://wraithnath.blogspot.com/2011/04/reportviewer-object-datasource-nested.html

The author also mentions that your classes will need a parameterless constructor but I have gotten it to work using classes without a default constructor. Still, if you have marked everything as serializable and are still seeing the "#Error" message, give it a try with parameterless constructors.


Unfortunately you can't (as yet), and the work-around is to create properties in the parent object.

More info:

  • https://connect.microsoft.com/VisualStudio/feedback/details/553592/accessing-nested-objects-in-data-source-of-local-report-does-not-function
  • http://blogs.msdn.com/b/brianhartman/archive/2010/10/27/nested-objects-in-local-mode.aspx


This is probably not an appropriate answer, but when I feel like the lack of material on this subject encourage me to post about my findings.

Let's say If I have a nested list of children object within the parent object. This is a very common situation for example, if you have an order object(parent), you will probably have a list of order items(children), how do you display all the information with the rdlc? There are two ways, 1 using subreport, and 2 is to use grouping. I realize they can both achieve the same thing which is displaying list of details on a report.

public class Order{
    public int OrderID {get; set;}
    public string Descrpition {get; set;}
    public List<OrderItem> OrderItems {get; set;}
}
public class OrderItem{
    public int OrderItemID {get; set;}
    public decimal Price{get; set;}
}

The easiest way is to use grouping. With grouping, you have to create a new datatype that contains the properties of the parent and children. I believe this way works with multi-level nested list of objects also. It might sound stupid, but most of the time you have to create a new datatype anyway because the types you need to display on the report are different from the business objects:

public class OrderReport{
    public int OrderID {get; set;}
    public string Description {get; set;}
    public int OrderItemID {get; set;}
    public decimal Price {get; set;}
}

Then on the rdlc, you just have to create parent row group and a child row group, Parent should be grouped by OrderID, the child row group should be set to "show details". I think you can do this multiple times to achieve multi-level nested list of objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜