This is a migrated thread and some comments may be shown as answers.

Sorting: NullReferenceException

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tomasz M.Lipiński
Top achievements
Rank 1
Tomasz M.Lipiński asked on 18 Nov 2010, 11:11 AM
Hi,

my grid displays - for example - organization units: OrgUnit objects. The OrgUnit class has a property "Manager" which contains an instance of the class "Person". This class has, in turn, a property named "FullName".
I want to display names of managers in one of the grid's columns. I bind this column with: "Manager.FullName". And it works perfectly - event for units with no manager.
Then, I want to sort my grid by this column. I put SortExpression="Manager.FullName". It works - but fails (NullReferenceException) when any of displayed units has no manager.
I understand that "Manager.FullName" can raise this exception when "Manager" is null but when displaying data it doesn't.
Can I solve this problem any way?
The workaround: define a special property "ManagerFullName" (return Manager == null ? "" : Manager.FullName) is not acceptable.

Regrads
Tomasz

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 24 Nov 2010, 08:02 AM
Hi Tomasz,

I tried to reproduce the issue in the sample attached - but had no success in that. Could you take a look at it and direct me how to modify it in order for the problem to be reproduced.

All the best,
Tsvetoslav
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Tomasz M.Lipiński
Top achievements
Rank 1
answered on 24 Nov 2010, 01:09 PM
Hi,

The attached example was not exact. The grid contains columns:
- Name
- Configuration.Description
- SkuAvailable.Minutes
Null was set for SkuAvailable.Minutes only. The point is to set null to SkuAvailable or Configuration.
I've improved your example by adding a single line of the constructor of the Movie class:
if (minutes.HasValue)
  _Configuration = new Config(descConfig);

Well, I've been surprised: it's my case of data but it works...
I've compared both RadGrids (yours and mine). The only difference was in EnableLinqExpressions attribute: your grid has "false" and mine has this attribute not set. I've put EnableLinqExpressions="false" to my RadGrid and it's started to work.
My grids don't use filtering at all. Is EnableLinqExpressions used for anything else?

Thanks for the solution - even if indirect :-)

Regards
Tomasz
Tags
Grid
Asked by
Tomasz M.Lipiński
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Tomasz M.Lipiński
Top achievements
Rank 1
Share this question
or