Cannot get child rows in Detail GridTableView to go into EDIT mode when parent row in MasterTableView is set to EDIT

2 posts, 0 answers
  1. Joanna LaForte
    Joanna LaForte avatar
    4 posts
    Member since:
    Jul 2009

    Posted 09 Nov 2009 Link to this post

    <telerik:RadGrid ID="grdUsers" runat="server" AutoGenerateColumns="False" Width="100%" AllowMultiRowEdit="True" GridLines="None">  
        <MasterTableView DataKeyNames="user_id" HierarchyLoadMode="Client" EditMode="InPlace">  
            <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridTemplateColumn> 
                    <HeaderTemplate> 
                        <asp:Label ID="lblSelect" runat="server" Text="Select:" meta:resourcekey="SelectLabel"></asp:Label> 
                        <asp:LinkButton ID="lnkbtnChkAll" runat="server" CommandArgument="All" CommandName="Check" 
                            Text="All" meta:resourcekey="Select_All"></asp:LinkButton> 
                        <asp:LinkButton ID="lnkbtnChkNone" runat="server" CommandArgument="None" CommandName="Check" 
                            Text="None" meta:resourcekey="Select_None"></asp:LinkButton> 
                        <asp:Button ID="btnDelete" runat="server" CommandArgument="Checked" CommandName="Delete" 
                            Text="Delete" meta:resourcekey="DeleteButton"></asp:Button> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:CheckBox ID="chkbxDelete" runat="server" Enabled='<%# Eval("allow_delete") %>' /> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="Email" UniqueName="UserEmail" DataField="user_email" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblEmailHdr" runat="server" Text="Email" meta:resourcekey="UserEmailLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("user_email") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:TextBox ID="fldEmail" runat="server" Text='<%# Eval("user_email") %>' ValidationGroup="vldgrpUser"></asp:TextBox> 
                        <asp:RequiredFieldValidator ID="rfvEmail" runat="server" ControlToValidate="fldEmail" 
                            ErrorMessage="* Required" ValidationGroup="vldgrpUser"></asp:RequiredFieldValidator> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="FirstName" UniqueName="FirstName" DataField="first_name" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblFNameHdr" runat="server" Text="First Name" meta:resourcekey="FirstNameLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblFName" runat="server" Text='<%# Eval("first_name") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:TextBox ID="fldFName" runat="server" Text='<%# Eval("first_name") %>' ValidationGroup="vldgrpUser"></asp:TextBox> 
                        <asp:RequiredFieldValidator ID="rfvFName" runat="server" ControlToValidate="fldFName" 
                            ErrorMessage="* Required" ValidationGroup="vldgrpUser"></asp:RequiredFieldValidator> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="LastName" UniqueName="LastName" DataField="last_name" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblLNameHdr" runat="server" Text="Last Name" meta:resourcekey="LastNameLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblLName" runat="server" Text='<%# Eval("last_name") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:TextBox ID="fldLName" runat="server" Text='<%# Eval("last_name") %>' ValidationGroup="vldgrpUser"></asp:TextBox> 
                        <asp:RequiredFieldValidator ID="rfvLName" runat="server" ControlToValidate="fldLName" 
                            ErrorMessage="* Required" ValidationGroup="vldgrpUser"></asp:RequiredFieldValidator> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="Role" UniqueName="UserRole" DataField="user_role_description" 
                    DataType="System.Int16">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblUserRoleHdr" runat="server" Text="Role" meta:resourcekey="UserRoleLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblUserRole" runat="server"></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:DropDownList ID="ddlUserRole" runat="server">  
                        </asp:DropDownList> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="User Name" UniqueName="UserName" DataField="user_name" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblUNameHdr" runat="server" Text="User Name" meta:resourcekey="UserNameLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblUName" runat="server" Text='<%# Eval("user_name") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:Label ID="lblUName" runat="server" Text='<%# Eval("user_name") %>'></asp:Label> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn UniqueName="UserStatus" DataField="user_status_id" DataType="System.Int16" 
                    Display="false">  
                </telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn HeaderText="Status" UniqueName="UserStatusDesc" DataField="user_status_description" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblUsrStatHdr" runat="server" Text="Status" meta:resourcekey="UserStatusLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblUsrStat" runat="server"></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:Label ID="lblUsrStat" runat="server"></asp:Label> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn UniqueName="IsTester" DataField="is_tester" DataType="System.Boolean" 
                    Display="false">  
                </telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn HeaderText="Browser" UniqueName="BrowserType" DataField="web_browser_type" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblBrowserHdr" runat="server" Text="Browser" meta:resourcekey="BrowserTypeLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblBrowser" runat="server" Text=""></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:Label ID="lblBrowser" runat="server" Text=""></asp:Label> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn HeaderText="IP" UniqueName="IPAddress" DataField="ip_address" 
                    DataType="System.String">  
                    <HeaderTemplate> 
                        <asp:Label ID="lblIPAddyHdr" runat="server" Text="IP" meta:resourcekey="IPAddressLabel"></asp:Label> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <asp:Label ID="lblIPAddy" runat="server" Text='<%# Eval("ip_address") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:Label ID="lblIPAddy" runat="server" Text='<%# Eval("ip_address") %>'></asp:Label> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn UniqueName="TemplatedEditUserColumn" HeaderStyle-CssClass="gridWBHeader3" 
                    ItemStyle-CssClass="gridWBRow3">  
                    <ItemTemplate> 
                        <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" meta:resourcekey="EditButton">  
                        </asp:Button> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:Button ID="btnUpdate" runat="server" Text="Save" CommandName="Update" meta:resourcekey="UpdateButton" 
                            ValidationGroup="vldgrpUser"></asp:Button> 
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" meta:resourcekey="CancelButton" 
                            CausesValidation="false"></asp:Button> 
                    </EditItemTemplate> 
                    <HeaderStyle CssClass="gridWBHeader3" /> 
                    <ItemStyle CssClass="gridWBRow3" /> 
                </telerik:GridTemplateColumn> 
            </Columns> 
            <NoRecordsTemplate> 
                <asp:Label ID="lblNoUsers" runat="server" Text="No users created."></asp:Label> 
            </NoRecordsTemplate> 
            <NestedViewSettings> 
                <ParentTableRelation> 
                    <telerik:GridRelationFields DetailKeyField="user_id" MasterKeyField="user_id" /> 
                </ParentTableRelation> 
            </NestedViewSettings> 
            <DetailTables> 
                <telerik:GridTableView runat="server" AutoGenerateColumns="false" Width="100%" Caption="Custom Defined Fields" 
                    EditMode="InPlace" Name="CustomUserFields">  
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="user_id" MasterKeyField="user_id" /> 
                    </ParentTableRelation> 
                    <Columns> 
                        <telerik:GridTemplateColumn UniqueName="CustomField">  
                            <ItemTemplate> 
                                <asp:Label ID="lblCustName" runat="server" Text='<%# Eval("custom_field_name") %>'></asp:Label> 
                                <asp:Label ID="lblCustValue" runat="server" Text='<%# Eval("custom_field_value") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <asp:Label ID="lblCustName" runat="server" Text='<%# Eval("custom_field_name") %>'></asp:Label> 
                                <asp:TextBox ID="fldCustValue" runat="server" Text='<%# Eval("custom_field_value") %>'></asp:TextBox> 
                                <asp:DropDownList ID="ddlCustValue" runat="server">  
                                </asp:DropDownList> 
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridEditCommandColumn ButtonType="PushButton" EditText="Edit" CancelText="Cancel" 
                            UpdateText="Update">  
                        </telerik:GridEditCommandColumn> 
                    </Columns> 
                    <NoRecordsTemplate> 
                        <asp:Label ID="lblNoCustFld" runat="server" Text="No custom data defined for this user."></asp:Label> 
                    </NoRecordsTemplate> 
                </telerik:GridTableView> 
            </DetailTables> 
        </MasterTableView> 
        <ClientSettings AllowColumnHide="true">  
        </ClientSettings> 
    </telerik:RadGrid> 
    I am trying to do the following in a RadGrid with a MasterTableView and a Detail GridTableView:

    1) User clicks EDIT on a parent row
    2) Parent row goes into EDIT mode
    3) Child rows, if any, also go into EDIT mode
    4) Child rows are displayed automatically if parent row goes into EDIT mode

    I have looked at and tried all of the currently posted methods for putting items (parent or child) into edit mode, including adding code to the PreRender event to add all of the child item indexes to the RadGridEditIndexes collection for the grid and rebinding without success.  If I put the code in the PreRender event, the indexes are properly added to the RadGrid.EditIndexes collection but a straight call to RadGrid.Rebind doesn't render the child rows.  If I, instead, call RadGrid.MasterTableView.DetailTables(0).Rebind, the detail rows are rendered but they are not in edit mode.  (I have also tried adding my code to the ItemCommand and EditCommand events for the grid, but these do not work either...)

    As a test, I commented out my PreRender code and added a GridEditCommandColumn to the Detail GridTableView.  I am able to expand/collapse the parent, click edit on the parent and then click edit on its children - they all go into EDIT mode after their respective EDIT buttons have been clicked, so I know it's possible to get them to all show up in EDIT mode...

    Any thoughts on how to accomplish this task is much appreciated, as I've spent 3 very unfruitful days trying to make it work.  Thanks!

    Notes: I have AllowMultiRowEdit set to TRUE for the grid, databinding is done server-side and I used the NeedDataSource event for databinding.

    Here's my PreRender code:

     

    Protected Sub grdUsers_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles grdUsers.PreRender  
            Try 
                If (Me.ProjectID > 0) Then 
                    Dim editItems() As Telerik.Web.UI.GridItem = grdUsers.MasterTableView.GetItems(Telerik.Web.UI.GridItemType.EditItem)  
                    For intCounter As Int32 = 0 To (editItems.Length - 1)  
                        editItems(intCounter).Edit = True 
                        editItems(intCounter).Expanded = True 
                        If editItems(intCounter).HasChildItems Then 
                            Dim customFields As Telerik.Web.UI.GridTableView = grdUsers.MasterTableView.Items(editItems(intCounter).ItemIndex).ChildItem.NestedTableViews(0)  
                            If Not (customFields Is NothingThen 
                                For Each fld As Telerik.Web.UI.GridItem In customFields.Items  
                                    grdUsers.EditIndexes.Add(editItems(intCounter).ItemIndex, grdUsers.MasterTableView.DetailTables(0).DetailTableIndex, fld.ItemIndex)  
                                Next fld  
                            End If 
                            editItems(intCounter).SetChildrenVisible(True)  
                        End If 
                    Next intCounter  
                    If (editItems.Length > 0) Then 
                        grdUsers.MasterTableView.DetailTables(0).DataSource = Nothing 
                        grdUsers.MasterTableView.DetailTables(0).Rebind()  
                    End If 
                End If 
            Catch ex As Exception  
                Throw New Exception("Error in grdUsers_PreRender() of module usrctrl_ProjectUsers: <br />" & ex.ToString)  
            End Try 
        End Sub 
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 12 Nov 2009 Link to this post

    Hi Joanna,

    I have posted a reply to your ticket on the same topic and would kindly ask you to leave our support communication to the formal support thread. For the convenience of other developers that might stumble upon the same issue, I am attaching the sample I prepared to this post as well.

    Thanks.

    Regards,
    Tsvetoslav
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top