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

[Solved] Heirarchical Grid: When editing parent, I expand the children grid and get an error rergarding DataKey Values

3 Answers 206 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric R
Top achievements
Rank 1
Eric R asked on 18 May 2009, 10:59 PM
OS: XP SP2
Browser: IE7
Telerik: 2008.2.826.20

I have a radgrid with an Heirarchy and get an error when I am editing a parent record if I try and expand the children below it. This error only appears when trying to edit the parent and attempt to expand the children.

1. I Click on the pencil Edit icon on the parent row.This will open the option to alter the Priority number (this is a read only field).
2. While this window is open, click on the + sign used to expand the children grid relating to this info.
3. An error appears:

"There was a problem extracting DataKeyValues from the DataSource.  Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource."


Code of my Radgrid:
<telerik:RadGrid ID="rgGroupInformation" runat="server" AutoGenerateColumns="False" 
                GridLines="None" Skin="Office2007" OnDetailTableDataBind="rgGroupInformation_DetailTableDataBind" 
                OnItemCommand="rgGroupInformation_ItemCommand" OnUpdateCommand="rgGroupInformation_UpdateCommand" 
                AllowPaging="True" Height="100%" Width="860px" OnNeedDataSource="rgGroupInformation_NeedDataSource">  
                <MasterTableView EditMode="InPlace" DataKeyNames="BatchGroupId">  
                    <DetailTables> 
                        <telerik:GridTableView runat="server" DataKeyNames="BatchId,AssignedUserId,DocumentCount" 
                            DataMember="GroupDetails" EditMode="InPlace">  
                            <ParentTableRelation> 
                                <telerik:GridRelationFields DetailKeyField="BatchGroupId" MasterKeyField="BatchGroupId" /> 
                            </ParentTableRelation> 
                            <RowIndicatorColumn> 
                                <HeaderStyle Width="20px" /> 
                            </RowIndicatorColumn> 
                            <ExpandCollapseColumn> 
                                <HeaderStyle Width="20px" /> 
                            </ExpandCollapseColumn> 
                            <Columns> 
                                <telerik:GridEditCommandColumn ButtonType="ImageButton">  
                                    <HeaderStyle Width="8%" /> 
                                </telerik:GridEditCommandColumn> 
                                <telerik:GridBoundColumn DataField="CustodianName" HeaderText="Custodian" ReadOnly="True" 
                                    UniqueName="Custodian">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridTemplateColumn HeaderText="Assigned User" UniqueName="UserName" DataField="UserName">  
                                    <EditItemTemplate> 
                                        <asp:DropDownList ID="UserName" runat="server" DataTextField="UserName" DataValueField="UserId" 
                                            DataSource='<%#FillddlUserName() %>' OnDataBound="UserName_DataBound">  
                                        </asp:DropDownList> 
                                    </EditItemTemplate> 
                                    <ItemTemplate> 
                                        <asp:Label runat="server" ID="UserName" Text='<%#bind("UserName") %>'></asp:Label> 
                                    </ItemTemplate> 
                                </telerik:GridTemplateColumn> 
                                <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" UniqueName="Priority">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridCheckBoxColumn DataField="OnHold" HeaderText="On Hold" UniqueName="OnHold">  
                                </telerik:GridCheckBoxColumn> 
                                <telerik:GridBoundColumn DataField="StartDocRange" HeaderText="Start Doc Range" ReadOnly="True" 
                                    UniqueName="StartDocRange">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="EndDocRange" HeaderText="End Doc Range" ReadOnly="True" 
                                    UniqueName="EndDocRange">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="DocumentCount" HeaderText="Document Count" UniqueName="DocCount">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridTemplateColumn UniqueName="TemplateColumn1">  
                                    <ItemTemplate> 
                                        <asp:LinkButton ID="imgBtnDelete" runat="server" CausesValidation="False" CommandArgument="" 
                                            CommandName="DeleteBatch" ForeColor="#044A7E" OnClientClick="javascript:if(!confirm('This action will delete the selected batch. Are you sure?')){return false;}" 
                                            Text="Delete" /> 
                                    </ItemTemplate> 
                                    <HeaderStyle Width="8%" /> 
                                </telerik:GridTemplateColumn> 
                            </Columns> 
                        </telerik:GridTableView> 
                    </DetailTables> 
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px" /> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn Visible="True">  
                        <HeaderStyle Width="20px" /> 
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <%--<telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Edit">  
                                        </telerik:GridEditCommandColumn>--%> 
                        <telerik:GridEditCommandColumn ButtonType="ImageButton">  
                            <HeaderStyle Width="8%" /> 
                        </telerik:GridEditCommandColumn> 
                        <telerik:GridBoundColumn DataField="CriteriaValue" HeaderText="Criteria Value" ReadOnly="True" 
                            UniqueName="CriteriaValue">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="BatchCount" HeaderText="Batch Count" ReadOnly="True" 
                            UniqueName="BatchCount">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" UniqueName="Priority" 
                            ReadOnly="false">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridCheckBoxColumn DataField="OnHold" HeaderText="On Hold" UniqueName="OnHold" 
                            ReadOnly="false">  
                            <HeaderStyle Width="10%" /> 
                        </telerik:GridCheckBoxColumn> 
                        <telerik:GridTemplateColumn UniqueName="TemplateColumn1">  
                            <ItemTemplate> 
                                <asp:LinkButton ID="imgBtnDelete" runat="server" CausesValidation="False" CommandArgument="" 
                                    CommandName="Delete" ForeColor="#044A7E" OnClientClick="javascript:if(!confirm('This action will delete the selected batch. Are you sure?')){return false;}" 
                                    Text="Delete" /> 
                            </ItemTemplate> 
                            <HeaderStyle Width="8%" /> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                    <EditFormSettings> 
                        <EditColumn UniqueName="EditCommandColumn1">  
                        </EditColumn> 
                    </EditFormSettings> 
                    <PagerStyle Mode="NextPrevAndNumeric" /> 
                </MasterTableView> 
                <ClientSettings> 
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                </ClientSettings> 
                <FilterMenu EnableTheming="True">  
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                </FilterMenu> 
            </telerik:RadGrid> 

I Stepped through my code on the back end and I have the following method where this error appears:
 protected void rgGroupInformation_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)  
    {  
        GridDataItem parentItem = e.DetailTableView.ParentItem as GridDataItem;  
 
        if (parentItem.Edit)  
        {  
            return;  
        }  
 
        if (e.DetailTableView.DataMember == "GroupDetails")  
        {  
            DataTable batchList = new DataTable("BatchList");  
            batchList = BindBatchDetailInformation(Convert.ToInt32(lblBatchCriteriaId.Text.Trim()));  
            e.DetailTableView.DataSource = batchList;  
        }  
 
 
    }  
 
Since my parentItem.Edit is true, it goes into the if statement and exits the rgGroupInformation_DetailTableDatabind() method. If I comment out this conditional, the radgrid will allow the child grid to expand and show the items. I suspect there has to be a more graceful way to exit this method.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 May 2009, 05:12 AM
Hi Eric,

I have found the following forum link which discusses a similar error. Go through it and see if it helps to some extent.
Error when detail table expanded in master table in edit mode

Shinu
0
Eric R
Top achievements
Rank 1
answered on 19 May 2009, 04:38 PM
Thank you Shinu.

I looked at the example code in the answer to the guys issue in that link and now the error appears in the pre render method of that radgrid. At this point, this isn't an answer to my issue, but I thank you for putting eyes to it with me.
0
Eric R
Top achievements
Rank 1
answered on 19 May 2009, 10:01 PM
I figured out the solution to my problem. I do a check in the ItemCommand method to see if they intend to Expand the child grid while the Parent is being edited. If so, I cancel the action and return:

if (e.CommandName.ToString() == "ExpandCollapse")  
{             
              
     if (e.Item.IsInEditMode == true)// do not let them expand the child grid if the parent is being edited  
     {  
          e.Canceled = true;  
          return;  
     }  
It works as I intend the ui to be for the end user. They now cannot expand the grid if editing a record and that record has children and the error message no longer appears.
Tags
Grid
Asked by
Eric R
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Eric R
Top achievements
Rank 1
Share this question
or