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

Problem sorting and filtering on a column bound to subobject property

3 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Taylor
Top achievements
Rank 1
Paul Taylor asked on 30 Jun 2010, 09:06 AM
Hi,

I have a grid bound to a strongly-typed list of business objects (List<BusinessObject>). The class BusinessObject has a property SubObject which may be null. One column of the grid binds to a string property called SubObject.Property.

The grid binds perfectly when it loads initially. However, if I try to filter or sort on the SubObject.Property column, it throws a Null Reference exception when there are any rows in the dataset that have SubObject = null.

I can see why that would be, but my question is, how do I get round it?

Regards,

Paul Taylor

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 30 Jun 2010, 01:24 PM
Hello Paul,

I tried to reproduce the problem in a sample of mine - but to no success. Could you take a look at the attached sample and let me know if I am missing something.

All the best,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul Taylor
Top achievements
Rank 1
answered on 30 Jun 2010, 02:25 PM
Hi Tsvetoslav,

If you make sure that not every record has an instantiated Configuration property (eg minor change to the Movie constructor, below) that would be a reasonable reconstruction of the scenario.

        if (descAvail == "Yes")
        {
            _Configuration = new Config(descConfig);
        }

However, when I add a reference to RadControls 2010.1.519.35 (for which I have a developers licence), I cannot reproduce the problem either.

My application (DNN module) is using 2010.1.309.35 which is the version shipped with DNN5.4.2. That is a restricted build so I can't test it with your app.

However, I can test my DNN module with the 519.35 build. When I did that, the same exception occurred. So that would seem to safely rules out a bug in the 309.35 build.

So, I then double-checked that the error only occurs when there is one row with a null value for the object on whose property I am filtering. And that is the case. The exception stack trace is below. Any ideas?

Message: DotNetNuke.Services.Exceptions.PageLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at lambda_method(ExecutionScope , LicenceInfo ) at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext() at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source) at lambda_method(ExecutionScope ) at System.Linq.EnumerableExecutor`1.Execute() at System.Linq.EnumerableExecutor`1.ExecuteBoxed() at System.Linq.EnumerableQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) at Telerik.Web.UI.GridDynamicQueryable.Count(IQueryable source) at Telerik.Web.UI.GridDataTableFromEnumerable.FillData35() at Telerik.Web.UI.GridDataTableFromEnumerable.FillData() at Telerik.Web.UI.GridResolveEnumerable.Initialize() at Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized() at Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) at Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) at Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) at Telerik.Web.UI.GridTableView.get_ResolvedDataSource() at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at Telerik.Web.UI.GridTableView.PerformSelect() at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() at Telerik.Web.UI.GridTableView.DataBind() at Telerik.Web.UI.GridTableView.Rebind() at Telerik.Web.UI.GridFilterCommandEventArgs.ExecuteCommand(Object source) at Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) at Telerik.Web.UI.GridItem.FireCommandEvent(String commandName, Object commandArgument) at Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---
0
Paul Taylor
Top achievements
Rank 1
answered on 30 Jun 2010, 02:54 PM
Looking at your code a bit more, I tried setting the EnableLinqExpressions="false" on my grid, and it solved the problem!

Thanks for your help.

Paul
Tags
Grid
Asked by
Paul Taylor
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Paul Taylor
Top achievements
Rank 1
Share this question
or