Problem adding record: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property

19 posts, 0 answers
  1. Tim
    Tim avatar
    3 posts
    Member since:
    Aug 2010

    Posted 03 Aug 2010 Link to this post

    I have a problem when selecting the button to insert a new record in a grid containing a drop-down control.  I'm not doing anything custom - all declaritive except for the code in the object data source controls.  When I click the button on the details table to insert a new record, I get the following error:

    DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'CountryCode'.

    Note that if there is already data in the source database table for the details table, everything works fine.  This only happens when there is no data in the database.  I have been spending a long time on this and can't see what the issue is.

     

    <%@ Page Title="TMS Carrier" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" %>
      
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <div class="gridHolderLarge">
            <h3 class="tableDesc">
                Carriers</h3>
            <telerik:RadGrid ID="grdCarrier" runat="server" AutoGenerateColumns="False" GridLines="None"
                DataSourceID="objDataCarrier">
                <MasterTableView AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
                    CommandItemDisplay="Top" DataKeyNames="CarrierId" DataSourceID="objDataCarrier"
                    EditMode="InPlace" NoMasterRecordsText="No carriers to display.">
                    <DetailTables>
                        <telerik:GridTableView runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                            AllowAutomaticUpdates="True" DataSourceID="objDataContact" NoDetailRecordsText="No contacts to display."
                            CommandItemDisplay="Top" DataKeyNames="ContactId,CountryCode">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="CarrierId" MasterKeyField="CarrierId" />
                            </ParentTableRelation>
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn>
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                            <CommandItemSettings AddNewRecordText="Add new contact" ShowRefreshButton="False" />
                            <Columns>
                                <telerik:GridBoundColumn DataField="Name" HeaderText="Contact Name" MaxLength="50"
                                    UniqueName="column4">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Position" HeaderText="Position" MaxLength="50"
                                    UniqueName="column5">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" MaxLength="50" UniqueName="column6">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Address" HeaderText="Address" MaxLength="50"
                                    UniqueName="column7" Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="City" HeaderText="City" MaxLength="50" UniqueName="column8"
                                    Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="State" HeaderText="State/Province" MaxLength="50"
                                    UniqueName="column1" Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="PostalCode" HeaderText="Postal Code" MaxLength="30"
                                    UniqueName="column2" Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridDropDownColumn DataField="CountryCode" DataSourceID="objDataCountry"
                                    HeaderText="Country" ListTextField="Country" ListValueField="CountryCode" 
                                    UniqueName="column" DefaultInsertValue="USA" Visible="False">
                                </telerik:GridDropDownColumn>
                                <telerik:GridBoundColumn DataField="Email" HeaderText="Email" MaxLength="200" UniqueName="column3">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Comment" HeaderText="Comment" MaxLength="4000"
                                    UniqueName="column10" Visible="False">
                                </telerik:GridBoundColumn>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/images/Cancel.gif"
                                    EditImageUrl="~/images/Edit.gif" InsertImageUrl="~/images/Update.gif" Reorderable="False"
                                    Resizable="False" UpdateImageUrl="~/images/Update.gif">
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmDialogType="RadWindow"
                                    ConfirmText="Are you sure you wish to permanently delete this contact?" ConfirmTitle="Delete Contact"
                                    ImageUrl="~/images/Delete.gif" Reorderable="False" Resizable="False" Text="Delete"
                                    UniqueName="column9">
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridButtonColumn>
                            </Columns>
                            <EditFormSettings>
                                <EditColumn UniqueName="EditCommandColumn1">
                                </EditColumn>
                            </EditFormSettings>
                        </telerik:GridTableView>
                    </DetailTables>
                    <CommandItemSettings AddNewRecordText="Add new carrier" />
                    <ExpandCollapseColumn Visible="True">
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Carrier" MaxLength="50" UniqueName="column1">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="AccountNumber" HeaderText="Account Number" MaxLength="50"
                            UniqueName="column2">
                        </telerik:GridBoundColumn>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/images/Cancel.gif"
                            EditImageUrl="~/images/Edit.gif" InsertImageUrl="~/images/Update.gif" Reorderable="False"
                            Resizable="False" UpdateImageUrl="~/images/Update.gif">
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmDialogType="RadWindow"
                            ConfirmText="Do you wish to permanently delete this carrier?" ConfirmTitle="Delete Carrier"
                            ImageUrl="~/images/Delete.gif" Reorderable="False" Resizable="False" Text="Delete"
                            UniqueName="column">
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                    <AlternatingItemStyle BackColor="#EAF2FA" Font-Bold="False" Font-Italic="False" Font-Overline="False"
                        Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </MasterTableView>
            </telerik:RadGrid>
            <asp:ObjectDataSource ID="objDataCarrier" runat="server" DeleteMethod="DeleteCarrier"
                InsertMethod="InsertCarrier" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCarriers"
                TypeName="Carrier" UpdateMethod="UpdateCarrier">
                <DeleteParameters>
                    <asp:Parameter Name="original_CarrierId" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="AccountNumber" Type="String" />
                    <asp:Parameter Name="original_CarrierId" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="AccountNumber" Type="String" />
                </InsertParameters>
            </asp:ObjectDataSource>
            <asp:ObjectDataSource ID="objDataContact" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetContacts" TypeName="CarrierContact">
                <SelectParameters>
                    <asp:Parameter Name="CarrierId" Type="Int32" DefaultValue="" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:ObjectDataSource ID="objDataCountry" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetCountries" TypeName="Country"></asp:ObjectDataSource>
        </div>
    </asp:Content>

     

     

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 06 Aug 2010 Link to this post

    Hello Tim,

    For more information about how to fix this error, please refer to the help article below:
    http://www.telerik.com/help/aspnet-ajax/grid-error-messages.html

    Give it a try and let me know if the issue persists.

    Kind regards,
    Pavlina
    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim
    Tim avatar
    3 posts
    Member since:
    Aug 2010

    Posted 23 Aug 2010 Link to this post

    I got distracted with other things but am back on this now and am still stuck.  This seems like a bug in the controls since this only happens when there's no data in the associated table.  I added the code below but I am still getting the error and I can't see where to go from here.  Note that I have since given the columns particular unique names since the original aspx code I posted.

     

     

    protected void grdCarrier_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if ((e.CommandName == RadGrid.InitInsertCommandName) && (e.Item.OwnerTableView.Name == "CarrierContact"))
        {
            e.Canceled = true;
            System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
            newValues["clmContactName"] = string.Empty;
            newValues["clmContactPosition"] = string.Empty;
            newValues["clmContactPhone"] = string.Empty;
            newValues["clmContactAddress"] = string.Empty;
            newValues["clmContactCity"] = string.Empty;
            newValues["clmContactState"] = string.Empty;
            newValues["clmContactPostalCode"] = string.Empty;
            newValues["clmContactCountry"] = "USA";
            newValues["clmContactEmail"] = string.Empty;
            newValues["clmContactComment"] = string.Empty;
            e.Item.OwnerTableView.InsertItem(newValues);
        }
    }

     

  5. Tim
    Tim avatar
    3 posts
    Member since:
    Aug 2010

    Posted 23 Aug 2010 Link to this post

    Okay, I beleive I found the solution.  I set the primary data key name in the values to something and that seems to work.  Thanks.

    protected void grdCarrier_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if ((e.CommandName == RadGrid.InitInsertCommandName) && (e.Item.OwnerTableView.Name == "CarrierContact"))
        {
            e.Canceled = true;
            System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
            newValues["CountryCode"] = string.Empty;
            e.Item.OwnerTableView.InsertItem(newValues);
        }
    }
  6. Lev Rosenblit
    Lev Rosenblit avatar
    16 posts
    Member since:
    May 2008

    Posted 28 Sep 2010 Link to this post

    Hi,
    I also get this error many times, and apply this solution.
    But this causes another problem:

    after applying this solution when i insert a value the insert form doesnt go away after submit, and the grid doesnt refresh.
    if i manualy rebind the grid in the OnInsertCommand handler - the grid refreshes and shows the new value - but the insert form is still visible - but this time it is empty.

    this is a very strange bug - and i asked about it 6 months ago, the reply i got was that i probably have script errors and thats why the edit form stays.
    I checked with firebug and chrome debugger - there are no script errors, and this bug happens only when appying the solution described in this forum for the 'GridInsertionObject' error.

    Lev Rosenblit
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 28 Sep 2010 Link to this post

    Hi Lev, 

    Can you please check whether you have set AllowAutomaticInserts property to true? If so set it to false and see if it helps to close the insert form.

    Also make sure that the record is added in the grid source and you do not have e.Canceled = true somewhere in your InsertCommand handler? 

    Moreover, you can test whether settings explicitly e.Item.OwnerTableView.IsItemInserted = false from within the InsertCommand handler makes a difference.

    Sincerely yours,
    Pavlina
    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
  8. Andrew
    Andrew avatar
    5 posts
    Member since:
    Jan 2011

    Posted 06 Jul 2011 Link to this post

    This should really be fixed... seems like a real hack to me.
  9. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 21 Sep 2011 Link to this post

    @Andrew

    +1 It sucks to have to keep doing
  10. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 22 Sep 2011 Link to this post

    Hello Steve,

    The reason for this error is that your grid instance can not bind a value for the newly inserted item through the Eval()/Bind() syntax you hard-coded (as you may have seen from the stack trace of the error). For more information you can refer to the following help article which explains the ways in which this error can be fixed.
    http://www.telerik.com/help/aspnet-ajax/grid-error-messages.html

    Greetings,
    Pavlina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  11. Hari krishna
    Hari krishna  avatar
    13 posts
    Member since:
    Jul 2012

    Posted 15 Oct 2012 Link to this post


    After clicking on refresh button i'm getting the below Error:
    DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'From'.

    If i had any data in my textbox i was not getting any error.

    The above solution for this fix is not working for many scenarios as In my cases the commandname property is different .So i can't check all the conditions like below.

     

     

     

    protected void grdAlphaSplits_ItemCommand(object source, GridCommandEventArgs e)

     {

       if (e.CommandName == RadGrid.InitInsertCommandName)//In my case there are many CommandName will come here

         {

                     e.Canceled = true;

             var newValues = new System.Collections.Specialized.ListDictionary();

                    newValues["From"] = string.Empty;

                    newValues["To"] = string.Empty;

                    e.Item.OwnerTableView.InsertItem(newValues);

        }

    }


    Your inputs will help...Thanks in advance

     

  12. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 Oct 2012 Link to this post

    Hi Hari,

    Another thing that you could try is to modify hard-coded bindings, as suggested in this forum thread:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/known-problem-databinding-telerik-web-ui-gridinsertionobject-does-not-contain-a-property-with-the-name-xxx.aspx

    Adding an empty object on InitInsert should also resolve the problem but from the provided code I cannot see what would cause this approach to fail. So, if none of the above helps, could you please send us your RadGrid declaration and related code behind, so we can look for other causes of this problem?

    Regards,
    Pavlina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  13. Joel
    Joel avatar
    19 posts
    Member since:
    Oct 2011

    Posted 22 Oct 2012 Link to this post

    Hi there:

    I'm also having this issue and it started happening today.

    The weird thing is in our development and test environment it works (IIS 6/MSSQL 8 R2); but in production environment isn't (IIS7/MSSQL EXPRESS 8 R2)

    I'm binding the data using a class and this is my grid

    <telerik:RadGrid runat="server" ID="rg1"
                AllowPaging="true" AllowCustomPaging="true" PageSize="10" AutoGenerateColumns="false" AllowSorting="true" ShowGroupPanel="true" AllowMultiRowSelection="true"
                AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" Skin="Office2007" EnableLinqExpressions="false"
                OnNeedDataSource="rg1_NeedDataSource" OnItemDataBound="rg1_ItemDataBound"
                OnInsertCommand="rg1_InsertCommand" OnUpdateCommand="rg1_UpdateCommand"
                OnDetailTableDataBind="rg1_DetailTableDataBind" OnItemCommand="rg1_ItemCommand"
                OnPreRender="rg1_PreRender" OnSortCommand="rg1_SortCommand"
            >
     
    <ClientSettings AllowColumnHide="true" AllowColumnsReorder="false" AllowDragToGroup="true">
                </ClientSettings>
                <GroupingSettings ShowUnGroupButton="true" />
                <MasterTableView EditMode="InPlace" Name="activities" DataKeyNames="PK" CommandItemDisplay="Top" CommandItemSettings-ShowRefreshButton="false" TableLayout="Fixed">
     
    <Columns>
                        <telerik:GridEditCommandColumn UniqueName="editCol" ButtonType="LinkButton" EditText="Modify" Visible="true" HeaderStyle-Width="100px" ></telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn UniqueName="ID" HeaderText="#" DataField="activityID" ReadOnly="false" Visible="false" HeaderStyle-Width="100px" ></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn UniqueName="active" HeaderText="Active" DataField="active" Visible="false" HeaderStyle-Width="70px" ></telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn UniqueName="priority" HeaderText="Priority" SortExpression="priority" GroupByExpression="Priority GROUP BY priority" HeaderStyle-Width="70px" >
                            <ItemTemplate><asp:Label runat="server" ID="rmlPriority" Text='<%# Eval("priority") %>'></asp:Label></ItemTemplate>
                            <EditItemTemplate><telerik:RadComboBox runat="server" ID="rcb_priority" DataTextField="SubKeyWord" DataValueField="KeyWord" OnDataBound="RadComboBox_DataBound"></telerik:RadComboBox></EditItemTemplate>
                        </telerik:GridTemplateColumn>
     
    <telerik:GridTemplateColumn UniqueName="notes" HeaderText="Notes" HeaderStyle-Width="350px" GroupByExpression="Notes GROUP BY notes">
                            <ItemTemplate>
                                    <div style="max-height:60px; overflow:auto;width:335px;">
                                        <div style="float:right; text-align:right;">
                                            <asp:LinkButton runat="server" ID="lbNewNote" Text="New Note" CommandName="insertNote"><img src="images/NewNote.png" alt="New Note" title="New Note" style="border:0;" /></asp:LinkButton>
                                        </div>
                                        <asp:Label runat="server" ID="lblNotes" Text='<%# DataBinder.Eval(Container.DataItem, "notes") %>'></asp:Label><br />
                                    </div>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox TextMode="MultiLine" runat="server" ID="txtBoxNotes" Rows="3" Text='<%# Eval("notes")%>' Width="330px" FocusedStyle-BackColor="#CEFFD8"></telerik:RadTextBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
     
    </Columns>
                </MasterTableView>
            </telerik:RadGrid>


    Any suggestion??

    Regards!!
  14. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 25 Oct 2012 Link to this post

    Hi Joel,

    Can you verify that you have examined the solution presented in this help article and it does not work for you?

    Greetings,
    Pavlina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  15. Joel
    Joel avatar
    19 posts
    Member since:
    Oct 2011

    Posted 25 Oct 2012 Link to this post

    Hello there Pavlina:

    I tried to add an "Empty Template" to RadGrid.InitInsertCommandName command but it didnt fix the issue.

    Anyway I found a fix, I just added the <InsertItemTemplate> to Every GridTemplateColumn in the grid and it worked.

    The annoying thing here is, this is the first time I had to do that and also is the first time I created an application using a Telerik project template so something must be wrong; but whatever the time has been spent trying to figuring out why isn't working the way how it was working before >.<.

    Thks anyway

    Regards!!!







    e.
  16. Josh
    Josh avatar
    7 posts
    Member since:
    Nov 2012

    Posted 17 Feb 2013 Link to this post

    I encountered this problem and found that, in my case, I was setting the grid's data source to the result of a Linq query without calling the ToList() method. Strangely, I was able to add records as long as data already existed in the grid, but clicking the Add button on an empty grid would cause the error described in this thread. As soon as I called the ToList() method on the Linq query, the error resolved itself. Hopefully this will be useful for some of you guys.
  17. Sasa
    Sasa avatar
    25 posts
    Member since:
    Jul 2013

    Posted 13 Sep 2013 Link to this post

    Yes, .ToList() solved my problem.

    Thanks Josh!
  18. Saravanan
    Saravanan avatar
    1 posts
    Member since:
    Nov 2013

    Posted 18 Nov 2013 Link to this post

    Thanks a lot!!

    .ToList() solved my problem as well.
  19. Peter
    Peter avatar
    98 posts
    Member since:
    Mar 2012

    Posted 31 Jul 2014 in reply to Saravanan Link to this post

    Thanks, I too needed to use "ToList()".
  20. Jonathan
    Jonathan avatar
    37 posts
    Member since:
    Sep 2012

    Posted 27 Jan 2015 Link to this post

    Thanks - The ToList() applied to my Linq query in my NeedDataSource event also solved this more me as well.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017