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

Problem with using DataKeys with NULL values

1 Answer 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Wood
Top achievements
Rank 1
Paul Wood asked on 16 Jul 2010, 11:56 AM
I have a DataGrid bound to a LinqDataSource and on my master table I have 3 DataKeys. One of these DataKeys is NULL for some of the rows in the grid. When I go to update a row in a popup form and submit the changes I get the dreaded "Object reference not set to an instance of an object" error (OriginalValueMatches is the last method in the stack trace).

Now if the grid doesn't contain any rows where that datakey is NULL, it works fine, alternatively if I remove that datakey it will also work fine. However it doesn't seem to matter if I'm updating a record where that field is NULL or not, it will still error should at least one row in the grid have a NULL datakey. The datakey corresponds with a GridDropDownColumn in the Grid (although it doesn't seem to matter if I have the Empty... attributes set or not or even if I remove this column totally from the grid)
<telerik:GridDropDownColumn DataSourceID="ldsBrand" DataField="BrandID" HeaderText="Brand Name" ListTextField="BrandName" ListValueField="BrandID" AllowFiltering="false" EnableEmptyListItem="true" EmptyListItemText="-- No Brand --" EmptyListItemValue="" ConvertEmptyStringToNull="true" EditFormColumnIndex="0" UniqueName="Brand" />

For the moment I've got around this problem with another database query to get the value when I need it, but would prefer to use DataKeys and would like to get to the bottom of this so I don't get stuck in the future. Is this a bug? Is there a workaround? Am I allowed to have a DataKey that is sometimes NULL?

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 22 Jul 2010, 10:07 AM
Hello Paul Wood,

I am afraid that the reported behavior is due to a LinqDataSource implementation specific and is not connected to RadGrid. As you have noticed the OriginalValueMatches() fails because it calls originalValue.Equals(value); Since originalValue is null, hence the error.

To verify that problem is not connected to RadGrid, you can try using a SqlDataSource instead of LinqDataSource. On my side this modification worked as expected.

I hope this helps.

Regards,
Martin
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
Tags
Grid
Asked by
Paul Wood
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or