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

[Solved] RadGrid bound to EntityDataSource

4 Answers 353 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin McMillen
Top achievements
Rank 1
Justin McMillen asked on 17 Feb 2010, 06:51 PM
I have a RadGrid that is bound to an EntityDataSource.  The RadGrid uses an edit form template and two of the controls are bound to Foreign Key tables(objects) of the parent entity object.  I have insert and update working.  But I get "Object reference not set to an instance of an object" when i perform a delete.  Does anyone know why this happens?

Below is a very rough markup of how my code is structured:

<telerik:radgrid id="myGrid" runat="server" DatasourceID="dsCustomers" AllowAutomaticInserts="true"
AllowAutomaticUpdates
="true" AllowAutomaticDeletes="true">
  <MasterTableView CommandItemDisplay="top" DataSourceId="dsCustomers" DataKeyNames="CustomerId" EditMode="EditForms">
    <Columns>
      <telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Edit" />
      <telerik:GridBoundColumn HeaderText="Title" DataField="Title.Description" />
      <telerik:GridBoundColumn HeaderText="Name" DataField="Name" />
      <telerik:GridButtonColumn ConfirmText="Delete this Customer?" ConfirmDialogType="Classic" ConfirmTitle="Delete"
        ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" />
    </Columns>
    <EditFormSettings EditFormType="Template">
      <FormTemplate>
        <table>
          <tr>
            <td>
              <telerik:RadComboBox id="cmbTitle" runat="server" DataSourceID="dsTitles" AppendDataBoundItems="true"
                DataTextField="Description" DataValueField="Id" SelectedValue='<%# Bind("Title.Id") %>' >
                <Items><telerik:RadComboBoxItem Value="0" Text="" Selected="true" /></Items>
              </telerik:RadcomboBox>
            </td>
            <td>
              <telerik:RadTextBox id="txtName" runat="server" Text='<% Bind("Name") %>;' />
            </td>
          </tr>
        </table>
      </FormTemplate>
    </EditFormSettings>
  </MasterTableView>
</telerik:radgrid>
<asp:EntityDataSource ID="dsCustomers" runat="server" ConnectionString="name=CustomerEntities"
DefaultContainerName="CustomerEntities" EnableUpdate="true" EnableInsert="true" EnableDelete="true"
EntitySetName="Customer" Include="Title" />
<asp:EntityDataSource ID="dsTitles" runat="server" ConnectionString="name=CustomerEntities"
DefaultContainerName="CustomerEntities" EntitySetName="Title" />

4 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 18 Feb 2010, 07:03 AM
Hi Justin,

 You need to make sure that you do not have any referential contstaints in the database that are preventing the delete operation. If so, you need to enable cascading deletes on the tables concerned.

I hope this helps.

Regards,
Tsvetoslav
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.
0
Justin McMillen
Top achievements
Rank 1
answered on 18 Feb 2010, 05:14 PM
Hi Tsvetoslav,
    Thank you for your quick response.  I don't think my problem is referential constraints because I can manually perform the delete in the DeleteCommand event of the RadGrid.  Do you have any idea why I can't delete the record from the EntityDataSource?
0
Justin McMillen
Top achievements
Rank 1
answered on 18 Feb 2010, 07:11 PM
Hi Tsvetoslav,
    I would also like to mention that I just tried the EntityDataSource bound to an ASP.NET GridView and the delete works fine with no additional code.  Is there a limitation with the RadGrid? 

Please See my code example below:

<asp:GridView ID="gvTest" runat="server" DataSourceID="eDsCustomers" AutoGenerateColumns="false" DataKeyNames="CustomerId">  
        <Columns> 
            <asp:TemplateField HeaderText="Title">  
                <ItemTemplate> 
                    <%# Eval("Title.Description") %> 
                </ItemTemplate> 
            </asp:TemplateField> 
            <asp:BoundField DataField="Name" HeaderText="Customer Name"  /> 
            <asp:CommandField ButtonType="Button" DeleteText="Delete"   ShowDeleteButton="true" />            
 
        </Columns> 
    </asp:GridView> 
 
<asp:EntityDataSource ID="eDsCustomers" runat="server" ConnectionString="name=CustomerEntities" EnableDelete="true" 
    DefaultContainerName="CustomerEntities" EnableUpdate="true" EnableInsert="true"  EntitySetName="Customer"   
    Include="Title" /> 
0
Tsvetoslav
Telerik team
answered on 23 Feb 2010, 11:10 AM
Hi Justin,

There is no known problem with RadGrid's delete operations on entity data-source. Could you try setting  EnableLinqExpressions=false for the grid and if the issue persists, please, send us a small runnable example of your implementation through a formal support ticket.

Thanks in advance.

Regards,
Tsvetoslav
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
Justin McMillen
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Justin McMillen
Top achievements
Rank 1
Share this question
or