VS.NET 2008 Report viewer control – Not so well documented issues and corresponding solutions

 

The problem definition this article address is to overcome the data binding issues in case the data is nothing / null for complex domain objects with parent-child relationships. This problem occurs only while binding the child object properties whose value is nothing / null. In such scenario, the report viewer will display as #Error in spite having expressions such as IIF(IsNothing(<objParent.Child.Property>),<True part>, <False part>)

 

VS.Net Report viewer control is pretty good to meet the reporting requirements in any project. It comes with VS.NET as a server control hence the learning curve in creating the reports also straight forward.

the http://www.gotreportviewer.com/ hosts plenty of samples and FAQs for different reporting requirements which are sufficient for most of the time.

In my recent project, we had a requirement to bind custom domain objects i.e. object data source to report control. The object relationship is multi level i.e. parent-child relationship as shown in the class model below

ClassDiagram1

The report in the designer mode is shown in the diagram

Report-Binding

In the above example marked in red color, I am binding the “d_Number” property of the “p_Uar” object which is a child object to the “p_UarTask”. In a best case scenario, the report is rendered correctly with the value but in case the child object is Nothing [or] Null in C# the value rendered  “#Error” as shown in the diagram below

#error

 

In order to overcome null/nothing, implemented the following expression

isNothing

The result of this implementation also rendered in #Error. I tried the same expression for the parent object and it worked but the same solution didn’t for any child objects.

After a hard time found out the solution which is creating and consuming custom code in the report itself (we can create macro like codes within the report and which gets compiled and executed using reflection by the VS.NET reporting API). The sample code Which I created and consumed from the report are shown below

code

GetUarNumber

This was very critical for us because we always deal with custom domain objects with complex relationships. Such kind of issues / known problems not given in the samples / FAQ’s which at least I could not found out easily hence posted my experience and solutions for others. I hope this helps.

One thought on “VS.NET 2008 Report viewer control – Not so well documented issues and corresponding solutions

  1. Hello! first, im sorry by my english.
    Your post was very help for me. It solved my problem.
    Just a comment, i was check my clase like “serializable”, i dont know why. After the solution works!
    Thanks from Argentina.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s