RadGrid绑定到EntityDataSource时自动删除时出错

时间:2011-09-02 16:45:30

标签: radgrid entitydatasource

我有一个绑定到EntityDataSource的RadGrid。一些列绑定到绑定实体的导航属性。当我尝试删除记录时,它会出现以下错误:

错误:Sys.WebForms.PageRequestManagerServerErrorException:在插入,更新或删除操作期间,在实体上找不到名为“Vehicle.VehicleNo”的属性。检查以确保指定为绑定表达式的属性可用于数据源。

我知道如果我选择使用普通外键ID,而不是导航属性,一切正常。如果我手动处理它,我可以轻松地使删除工作。但我只是认为必须有一种方法让自动删除工作。任何想法?

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" 
                    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                    DataSourceID="EntityDataSource1" GridLines="None" ShowGroupPanel="True" Skin="Hay"
                    OnItemUpdated="RadGrid1_ItemUpdated" 
                    OnItemInserted="RadGrid1_ItemInserted" OnItemCommand="RadGrid1_ItemCommand"
                    Height="400px" Width="700px" CellSpacing="0">
                    <MasterTableView DataKeyNames="ADChecklistId" DataSourceID="EntityDataSource1" CommandItemDisplay="Top">
                        <CommandItemSettings AddNewRecordText="Add New Aerial Device Checklist" ShowRefreshButton="false"
                            ShowAddNewRecordButton="true"></CommandItemSettings>
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                                HeaderText="Edit">
                            </telerik:GridEditCommandColumn>
                            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="DeleteCommandColumn" HeaderText="Delete" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?">
                            </telerik:GridButtonColumn>
                            <telerik:GridBoundColumn DataField="Vehicle.VehicleNo" FilterControlAltText="Filter VehicleNo column"
                                HeaderText="VehicleNo" SortExpression="Vehicle.VehicleNo" UniqueName="Vehicle.VehicleNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Employee.FirstName" FilterControlAltText="Filter FirstName column"
                                HeaderText="FirstName" SortExpression="Employee.FirstName" UniqueName="Employee.FirstName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Employee.LastName" FilterControlAltText="Filter LastName column"
                                HeaderText="LastName" SortExpression="Employee.LastName" UniqueName="Employee.LastName">
                            </telerik:GridBoundColumn>  
                            <telerik:GridBoundColumn DataField="Utility.UtilityName" HeaderText="Utility" SortExpression="Utility.UtilityName" UniqueName="Utility.UtilityName" >
                            </telerik:GridBoundColumn>                                
                            <telerik:GridDateTimeColumn DataField="CreatedOn" DataType="System.DateTime" FilterControlAltText="Filter CreatedOn column"
                                HeaderText="CreatedOn" SortExpression="CreatedOn" UniqueName="CreatedOn" DataFormatString="{0:MM/dd/yy}">
                            </telerik:GridDateTimeColumn>
                            <telerik:GridBoundColumn DataField="CreatedBy" FilterControlAltText="Filter CreatedBy column"
                                HeaderText="CreatedBy" SortExpression="CreatedBy" UniqueName="CreatedBy">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="ModifiedOn" DataType="System.DateTime" FilterControlAltText="Filter ModifiedOn column"
                                HeaderText="ModifiedOn" SortExpression="ModifiedOn" UniqueName="ModifiedOn" DataFormatString="{0:MM/dd/yy}">
                            </telerik:GridDateTimeColumn>
                            <telerik:GridBoundColumn DataField="ModifiedBy" FilterControlAltText="Filter ModifiedBy column"
                                HeaderText="ModifiedBy" SortExpression="ModifiedBy" UniqueName="ModifiedBy">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <ClientSettings AllowDragToGroup="True" EnablePostBackOnRowClick="true">
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        <Resizing AllowColumnResize="true" ClipCellContentOnResize="false" />
                    </ClientSettings>
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                </telerik:RadGrid>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" AutoGenerateWhereClause="True"
    ConnectionString="name=MSOpsEntities" DefaultContainerName="MSOpsEntities" 
    EnableFlattening="False" EnableDelete="True" EntitySetName="ADChecklists"
    Include="Vehicle, Employee, Utility" OrderBy="it.CreatedOn DESC" 
    OnSelecting="EntityDataSource1_Selecting" 
    ondeleting="EntityDataSource1_Deleting">
    <WhereParameters>
        <asp:SessionParameter Name="UtilityId" SessionField="utilityId" Type="Int32" />
    </WhereParameters>
</asp:EntityDataSource>

1 个答案:

答案 0 :(得分:0)

尝试在包含导航属性的ReadOnly="true"上设置GridBoundColumn,这对我有用。也许您可以使用Eval而不是Bind

的模板列