The basic layout of the page is that we have a list of security roles, and each role is granted a set of permissions. If you delete one of the permissions, you get an InvalidOperationException with the following message: "Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation."
However, deleting a record from a nested table works if it's the last table in the list, or if you first add a record to that table.
<telerik:RadGrid runat="server" ID="securityRolesRadGrid" Skin="Vista" AllowSorting="true"
DataSourceID="rolesDataSource" Width="775px" AutoGenerateColumns="false">
<MasterTableView CommandItemDisplay="Top" HierarchyDefaultExpanded="false" HierarchyLoadMode="Client" InsertItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add new role"
AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
DataKeyNames="RoleID" EditMode="InPlace">
<ExpandCollapseColumn Visible="True"></ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-CssClass="rgHeader rgImgCol" ItemStyle-CssClass="rgImgCol"></telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Role"></telerik:GridBoundColumn>
<telerik:GridDropDownColumn HeaderText="Scope" DropDownControlType="DropDownList" DataSourceID="scopesDataSource" DataField="ScopeID" ListTextField="Name" ListValueField="ScopeID"></telerik:GridDropDownColumn>
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" ColumnEditorID="fullWidthTextboxEditor"></telerik:GridBoundColumn>
<telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this Role? Users assigned to this role may lose permissions on the site." ConfirmTitle="Delete" CommandName="Delete" ButtonType="ImageButton" HeaderStyle-CssClass="rgHeader rgImgCol" ItemStyle-CssClass="rgImgCol"></telerik:GridButtonColumn>
</Columns>
<DetailTables>
<telerik:GridTableView DataSourceID="rolePermissionsDataSource" Width="100%" NoDetailRecordsText="No permissions assigned for this role." CommandItemSettings-AddNewRecordText="Add new permission"
AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
DataKeyNames="RolePermissionID,RoleID" CommandItemDisplay="Top" InsertItemDisplay="Top" EditMode="InPlace">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="RoleID" MasterKeyField="RoleID" />
</ParentTableRelation>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-CssClass="rgHeader rgImgCol" ItemStyle-CssClass="rgImgCol"></telerik:GridEditCommandColumn>
<telerik:GridDropDownColumn HeaderText="Permission" DropDownControlType="DropDownList" DataSourceID="permissionsDataSource" DataField="PermissionID" ListTextField="Permission" ListValueField="PermissionID"></telerik:GridDropDownColumn>
<telerik:GridDropDownColumn HeaderText="Project Phase" DropDownControlType="RadComboBox" DataSourceID="projectStatusesDataSource" DataField="ProjectStatusID" ListTextField="Status" ListValueField="ProjectStatusID" EnableEmptyListItem="true" EmptyListItemText="" EmptyListItemValue="" ConvertEmptyStringToNull="true"></telerik:GridDropDownColumn>
<telerik:GridButtonColumn ConfirmText="Delete Permission?" ConfirmTitle="Delete" CommandName="Delete" ButtonType="ImageButton" HeaderStyle-CssClass="rgHeader rgImgCol" ItemStyle-CssClass="rgImgCol"></telerik:GridButtonColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
<asp:LinqDataSource runat="server" ID="rolesDataSource"
ContextTypeName="SecurityDataContextEx"
TableName="SecurityRoles"
EnableDelete="true" EnableInsert="true" EnableUpdate="true">
</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="scopesDataSource"
ContextTypeName="SecurityDataContextEx"
TableName="SecurityRoleScopes">
</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="rolePermissionsDataSource"
ContextTypeName="SecurityDataContextEx"
TableName="SecurityRolePermissions"
EnableDelete="true" EnableInsert="true" EnableUpdate="true"
Where="RoleID == @RoleID">
<WhereParameters>
<asp:Parameter Name="RoleID" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="permissionsDataSource"
ContextTypeName="SecurityDataContextEx"
TableName="SecurityPermissions"
Where="@isSiteLevelScope && isSiteLevelScope == true ||
@isProjectLevelScope && isProjectLevelScope == true ||
@isProjectOwnerLevelScope && isProjectOwnerLevelScope == true">
<WhereParameters>
<asp:Parameter Name="isSiteLevelScope" Type="Boolean" DefaultValue="false" />
<asp:Parameter Name="isProjectLevelScope" Type="Boolean" DefaultValue="false" />
<asp:Parameter Name="isProjectOwnerLevelScope" Type="Boolean" DefaultValue="false" />
</WhereParameters>
</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="projectStatusesDataSource"
ContextTypeName="SecurityDataContextEx"
TableName="ProjectStatus" Where="Disabled==null || Disabled==false" OrderBy="SortOrder">
</asp:LinqDataSource>