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

Deleting from nested GridTableViews

5 Answers 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dylan
Top achievements
Rank 1
Dylan asked on 15 Jan 2010, 04:36 PM
We've having a problem with deleting rows from a GridTableView nested inside a RadGrid.

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>

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 21 Jan 2010, 05:08 PM
Hi Dylan,

The exception you are getting seems to originate from the LinqDataSource. Here is an external link for more info:

Social MSDN

It may turn out that this issue is not related to RadGrid. Please try setting up the same scenario using standard ASP.NET server controls like GridView, Repeater or others. The sample markup you provided seems fine on examination.

All the best,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ben Hill
Top achievements
Rank 1
answered on 06 May 2010, 05:31 AM
I solved this issue by using the EXACT casing I had in the database and putting it in the
RadGrid's MasterTableView DataKeyNames property.
Before:
<MasterTableView DataKeyNames="TagId">

after:

<MasterTableView DataKeyNames="TagID">

I bet this will fix your issue.
0
Flappie
Top achievements
Rank 1
answered on 02 Jul 2010, 01:44 AM
Hello,

I'm having the same problem as Dylan, but it's not the same as the problem that Ben Hill was proposing a solution for.

Basically the nested items that were selected last can be deleted. In Client and ServerBind this means that only the items inside the bottom master item can be deleted. With ServerOnDemand, the items inside the master item that was expanded last can be deleted.

If the DataKeyNames are set incorrectly, none of the items can be deleted, but now only the latest can be deleted.

It seems to only preserve the last select in viewstate.
0
Veli
Telerik team
answered on 02 Jul 2010, 11:44 AM
Hello Flappie,

What happens when items cannot be deleted? Do you get any server or client-side errors? If you are using AJAX, consider disabling all AJAX functionality and see if it makes any difference without AJAX. Thus, you can eliminate any potential AJAX-related issue in this scenario.

If you are getting the same exception as Dylan, you may want to check the LinqDataSourceView bug discussion I linked to in my previous post. If the problem persists, consider opening a regular support ticket where you can send us a stripped down runnable project we can debug locally. This would be the optimal approach for us, so that we can get to the cause of this problem and advise you further.

Veli
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
Veli
Telerik team
answered on 05 Jul 2010, 11:30 AM
Hi guys,

We were able to identify the cause of this issue. The LinqDataSource, by default, stores the original data key values of the selected items in the ViewState. The nested tables are all wired to a single LinqDataSource. This combination means that multiple SELECTs will be executed from the related LinqDataSource control. Thus, you can note that the ViewState of the LinqDataSource will store the data key values of the last retrieved data set from the last SELECT operations. Hence, you are able to delete the last expanded child item OK, but the previous ones do not have a matching data key values collection in the LinqDataSource ViewState.

To work around this limitation of the LinqDataSource control, you need to set StoreOriginalValuesInViewState="false" for the LinqDataSource control binding to the nested tables. In this way, the data key values of the deleted / updated item will be provided by RadGrid automatically, so no data values will be stored in the ViewState.

Kind regards,
Veli
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
Dylan
Top achievements
Rank 1
Answers by
Veli
Telerik team
Ben Hill
Top achievements
Rank 1
Flappie
Top achievements
Rank 1
Share this question
or