Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

I really like working with the Telerik ASP.NET AJAX controls. However, I keep forgetting about a problem in the RadGrid that occurs when trying to add a new record using EntityDataSource. If there aren’t any records yet, and you click Add Record, you often get this:

DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name ‘<fieldname>'. 

The workaround is to manually initialize the object being inserted. Here’s the routine (VB) for my future reference and yours:

Protected Sub RadGrid1_ItemCommand _
(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) _
    Handles RadGrid1.ItemCommand
     ' For error 'Telerik.WebControls.GridInsertionObject' does not contain a property
     ' Handles the case where you are adding a new item to the grid where
     ' none exists yet. The purpose is to create a dummy collection of values
     ' to prefill the form
     If e.CommandName = RadGrid.InitInsertCommandName Then
         e.Canceled = True
         Dim newValues As System.Collections.Specialized.ListDictionary = _
         New System.Collections.Specialized.ListDictionary()
         newValues("Note") = ""
         newValues("DisplayOrder") = 0
         newValues("ID") = 0
         'Insert the item and rebind
         e.Item.OwnerTableView.InsertItem(newValues)
     End If
End Sub

Full Disclosure: Telerik gave me a copy of their controls as a perk for being a Microsoft MVP for ASP.NET.

Ken

Published Friday, October 02, 2009 9:01 AM by Ken Cox [MVP]

Comments

# re: Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

Monday, December 07, 2009 4:21 PM by Claudia

Thank you very much!, I was 2 days old with this problem and was not finding the why ... thanks to God that generous people exist in knowledge like your.

# re: Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

Sunday, January 10, 2010 8:44 AM by Pavel

Or, if the dataitem is your object, you can do like that:

if (e.CommandName == RadGrid.InitInsertCommandName)

               {

                   e.Item.OwnerTableView.InsertItem(new YourObject());  

               }

Sorry for my english...

# re: Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

Thursday, April 01, 2010 1:01 PM by sajid

Thank you so so somuch....

been hunting for this solution 4 some time now

# re: Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

Monday, June 21, 2010 1:21 AM by Alistair Crawford

You can often solve this problem by setting the DefaultInsertValue property of all relevant columns in the radgrid to an appropriate value on the aspx page.

# re: Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

Saturday, September 25, 2010 10:29 AM by Nicolo

Thanks, also to Pavel.

# re: Fixing the ‘Telerik.WebControls.GridInsertionObject does not contain a property’ Error

Monday, December 20, 2010 11:45 PM by Naveen

Thanks you so much!!

Leave a Comment

(required) 
(required) 
(optional)
(required)