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

[Solved] RadGrid sorting with nullobjects

5 Answers 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 31 Mar 2009, 10:00 AM
Hi,

I have a problem sorting columns in a radgrid, with null objects in it.
The initial binding is all fine, and no problems.Not untill I try to sort a column with null objects in it.

I programmaticly create the columns like:

 

GridBoundColumn boundColumn = new GridBoundColumn();

 

view.Columns.Add(boundColumn);

 

boundColumn.DataField = "My.Custom.Object"; (note that Custom willbe null at some times, and therefore we cant sort the column).

The error occurs when I rebind the grid in Page_PreRender.

RadGrid1.DataSource = SomeDataSource;

 

try

 

 

 

 

{

 

 

    RadGrid1.Rebind();

}

 

 

 

catch (Exception e)

{

 

    // We will have a "Object reference not set to an instance of an object" error here...

 

}

 

 

Any way to get around this error?

Regards
Andreas Clausen

 

 

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 31 Mar 2009, 11:38 AM
Hi Andreas,

I am not sure whether this suggestion will work or not. But you may try the following code snippet in the ItemDataBound event to replace the cell having null value with   and see whether Sorting of the GridBoundColumn is working.

CS:
 
 
  protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item["colUniqueName"].Text == null
            { 
                item["colUniqueName"].Text = " "
            } 
        } 
        
    } 


Shinu
0
Andreas
Top achievements
Rank 1
answered on 31 Mar 2009, 11:59 AM

Hi Shinu,

If I loop through all the dataitems in the _ItemDataBound event, no items (.Text) has null values.

They will have   as default, and in my case they will be "--" (boundColumn.EmptyDataText = "--").
So unfortunately nothing will change (I tried) with the code you pasted.

 

Strange thing is that the bind itself, works fine with nullable objects, but the sorting does not :S

 

Any other ideas/workarounds?

 

Regards

Andreas Clausen

0
Andreas
Top achievements
Rank 1
answered on 13 Apr 2009, 10:01 AM
No one else with nullable sorting problems?

Scenario is (thought):

 

DataField

 

="House.Door.Size" <- (We have a problem when sorting by this, and the house has no doors (House.Door is null) )

// Andreas Clausen

0
Accepted
Sebastian
Telerik team
answered on 13 Apr 2009, 10:27 AM
Hello Andreas,

Can you please check whether the same issue appear when binding your custom collection to regular MS GridView control? Furthermore, in case you use the .NET 3.5 version of the grid, does setting EnableLinqExpressions = false for the control addresses the error in question?

Let us know what your findings are.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Andreas
Top achievements
Rank 1
answered on 13 Apr 2009, 06:32 PM
Hi Sebastian

Setting the property EnableLinqExpressions = False, actually did the trick.

Was doing alot of tests on both yours and MS gridview, but never got it up and working.
Guess you saved me from nearly going insane :)
Thanks alot for your help on this one.

// Andreas Clausen
Tags
Grid
Asked by
Andreas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Andreas
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or