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>
I have a RadGrid that's bound to EntityDataSource. A few of the columns are bound to navigation properties of the bound entity. When I try to delete a record, it gives the following error:
Error: Sys.WebForms.PageRequestManagerServerErrorException: A property named 'Vehicle.VehicleNo' was not found on the entity during an insert, update, or delete operation. Check to ensure that properties specified as binding expressions are available to the data source.
I know if I choose to use the plain foreign key IDs, instead of the navigation properties, everything works. I can easily get the delete to work if I handle it manually. But I"m just thinking there's got to be a way for the automatic delete to work too. Any ideas?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在包含导航属性的
GridBoundColumn
上设置ReadOnly="true"
,这对我有用。也许您也可以将模板列与Eval
一起使用,而不是Bind
Try setting
ReadOnly="true"
on theGridBoundColumn
s containing the navigation properties, this worked for me. Maybe also you could use template columns withEval
rather thanBind