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

[Solved] e.NewObject is null in LinqDataSource_Inserting event

1 Answer 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Han
Top achievements
Rank 1
Han asked on 18 May 2009, 07:58 PM

Hi, all:

I got the "A critical error has occurred. Object reference not set to an instance of an object." error message, and this is b/c the e.NewObject within the LinqDataSource_Inserting event is null when I am inserting data.

The background of the problem:

I have two RadGrids. The top one contains contacts, and the bottom one contains one or more notes concerning a selected contact from the top grid. The user can create his own list of note subjects, from which he can choose only one when creating a new note. This list of subjects is bound to a dropdownlist with the markup below:

<asp:DropDownList ID="ddl_subjects" runat="server"

DataSourceID="LinqDS_Subjects" DataTextField="Subject"

DataValueField="SubjectId"

SelectedValue='<%# Bind("SubjectId") %>'

AppendDataBoundItems="True" >

<asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem>

</asp:DropDownList>

Every time when I create a new note, if I pick one of the bound values, the note inserts fine. But whenever I pick "Select", which has a value of null, to intentionally not assign a subject to the note, I get that error message. I spent hours debugging, but to no avail. So your help is greatly appreciated.

 Han

 

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 21 May 2009, 02:52 PM
Hello Zhe,

As long as the underlying datatabase has the subject field as nullable, there should be no problem for the LinqDataSource to insert a null value into it. Please, make sure that it does allow null values.

Other than that, it is very difficult from the supplied information to pinpoint the issue. If the problem persists I'd suggest you to open a formal support ticket and send a test project so that we can debug it and fix the problem.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Han
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or