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

Edit mode Issue in hierarchy grid

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
zel
Top achievements
Rank 1
zel asked on 06 Oct 2010, 04:23 AM
Hello Everyone,

I have a weird problem in editing a detail row from hierarchy grid.

Please check on attached screenshot for reference and for more details.

ASPX:
<rad:RadGrid runat="server" ID="gridCPDiag"
AllowPaging="True" AllowSorting="True"  PageSize="15"       AutoGenerateColumns="False" GridLines="None" BorderStyle="None"            Skin="Outlook" AllowMultiRowEdit="true" AllowMultiRowSelection="true"
OnNeedDataSource="gridCPDiag_NeedDataSource"
OnDetailTableDataBind="gridCPDiag_DetailTableDataBind"
OnInsertCommand="gridCPDiag_InsertCommand"
OnDataBound="gridCPDiag_Databound"
OnUpdateCommand="gridCPDiag_UpdateCommand"
OnItemCreated="gridCPDiag_ItemCreated"
OnDeleteCommand="gridCPDiag_DeleteCommand" OnItemDataBound="gridCPDiag_ItemDataBound"
OnPreRender="gridCPDiag_PreRender" 
OnItemCommand="gridCPDiag_ItemCommand">
            <MasterTableView Name="Master" DataKeyNames="cpd_id" CommandItemDisplay="Top" EditMode="InPlace" Width="100%">
                <CommandItemTemplate>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width:60%">
                                <div style="padding:3px 4px 3px 4px">
                                    <table border="0" cellpadding="1" cellspacing="1">
                                        <tr style="font: normal 11px tahoma, Verdana, Helvetica, Sans-serif;vertical-align:middle">
                                            <td>
                                                <div class="toolbarIconDivider">|</div>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="master_btnAdd" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="InitInsert" ><img style="border:0px" alt="" src="../images/addemail.gif" /> Add</asp:LinkButton>
                                                <asp:LinkButton ID="master_lnkPerformInsert" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="PerformInsert" Visible="false"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                            </td>
                                            <td>
                                                <div class="toolbarIconDivider">|</div>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="master_btnEditSelected"  CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="EditSelected" ><img style="border:0px" alt="" src="../images/edit.gif" /> Edit</asp:LinkButton>
                                                <asp:LinkButton ID="master_btnUpdateEdited" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Update" Visible="false"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                <asp:LinkButton ID="master_btnCancel" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="CancelAll"  Visible="false" CausesValidation="false"><img style="border:0px" alt="" src="../images/cancel.gif" /> Cancel</asp:LinkButton>
                                            </td>
                                            <td>
                                                <div class="toolbarIconDivider">|</div>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="master_btnDelete" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('Are you sure you want to delete this Clinical Pathway?')" ><img style="border:0px" alt="" src="../images/delete.gif" /> Delete</asp:LinkButton>
                                            </td>
                                            <td>
                                                <div class="toolbarIconDivider">|</div>
                                            </td>
                                            <td align="right">
                                               <asp:LinkButton id="master_PrintFriendly" ForeColor="Black" runat="server" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" ><img  style="border:0px" alt="" src="../images/print.gif" /> Printer Friendly Version</asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    </table>
                 </CommandItemTemplate>
                 <DetailTables>
                    <rad:GridTableView Name="Detail2"  DataKeyNames="cp_id" DataMember="visit"  CommandItemDisplay="Top" EditMode="InPlace" Width="100%">
                    <CommandItemTemplate>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width:60%">
                                    <div style="padding:3px 4px 3px 4px">
                                        <table border="0" cellpadding="1" cellspacing="1">
                                            <tr style="font: normal 11px tahoma, Verdana, Helvetica, Sans-serif;vertical-align:middle">
                                                <td>
                                                    <div class="toolbarIconDivider">|</div>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="det2_btnAdd" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="InitInsert"><img style="border:0px" alt="" src="../images/addemail.gif" /> Add</asp:LinkButton>
                                                    <asp:LinkButton ID="det2_lnkPerformInsert" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="PerformInsert" Visible="false"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                </td>
                                                <td>
                                                    <div class="toolbarIconDivider">|</div>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="det2_btnEditSelected"  CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="EditSelected" ><img style="border:0px" alt="" src="../images/edit.gif" /> Edit</asp:LinkButton>
                                                    <asp:LinkButton ID="det2_btnUpdateEdited" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Update" Visible="false"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                    <asp:LinkButton ID="det2_btnCancel" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="CancelAll"  Visible="false" CausesValidation="false"><img style="border:0px" alt="" src="../images/cancel.gif" /> Cancel</asp:LinkButton>
                                                </td>
                                                <td>
                                                    <div class="toolbarIconDivider">|</div>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="det2_btnDelete" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Delete"  OnClientClick="javascript:return confirm('Are you sure you want to delete this/these Clinical Pathway Visit Frequency?')" ><img style="border:0px" alt="" src="../images/delete.gif" /> Delete</asp:LinkButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        </table>
                     </CommandItemTemplate>                   
                        <DetailTables>
                            <rad:GridTableView  Name="Detail3" DataKeyNames="cpi_id" DataMember="instruction" CommandItemDisplay="Top" EditMode="InPlace" Width="100%">
                            <CommandItemTemplate>
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width:60%">
                                        <div style="padding:3px 4px 3px 4px">
                                            <table border="0" cellpadding="1" cellspacing="1">
                                                <tr style="font: normal 11px tahoma, Verdana, Helvetica, Sans-serif;vertical-align:middle">
                                                    <td>
                                                        <div class="toolbarIconDivider">|</div>
                                                    </td>
                                                    <td>
                                                        <asp:LinkButton ID="det3_btnAdd" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="InitInsert" ><img style="border:0px" alt="" src="../images/addemail.gif" /> Add</asp:LinkButton>
                                                        <asp:LinkButton ID="det3_lnkPerformInsert" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="PerformInsert" Visible="false"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                    </td>
                                                    <td>
                                                        <div class="toolbarIconDivider">|</div>
                                                    </td>
                                                    <td>
                                                        <asp:LinkButton ID="det3_btnEditSelected"  CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="EditSelected" ><img style="border:0px" alt="" src="../images/edit.gif" /> Edit</asp:LinkButton>
                                                        <asp:LinkButton ID="det3_btnUpdateEdited" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Update" Visible="false"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                        <asp:LinkButton ID="det3_btnCancel" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="CancelAll" Visible="false" CausesValidation="false"><img style="border:0px" alt="" src="../images/cancel.gif" /> Cancel</asp:LinkButton>
                                                    </td>
                                                    <td>
                                                        <div class="toolbarIconDivider">|</div>
                                                    </td>
                                                    <td>
                                                        <asp:LinkButton ID="det3_btnDelete" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Delete"  OnClientClick="javascript:return confirm('Are you sure you want to delete this Clinical Pathway Instruction?')" ><img style="border:0px" alt="" src="../images/delete.gif" /> Delete</asp:LinkButton>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                            </CommandItemTemplate>
                             
                            <Columns>
                            <rad:GridBoundColumn DataField="cpi_id" HeaderText="CPI_ID" UniqueName="CPI_ID" Visible="false"></rad:GridBoundColumn>
                            <rad:GridBoundColumn DataField="instructions" HeaderText="instructions" UniqueName="instructions" Visible="false"></rad:GridBoundColumn>
                            <rad:GridTemplateColumn HeaderText="Instructions" UniqueName="instructions" DataField="instructions">
                                <ItemTemplate>
                                    <%# DataBinder.Eval(Container.DataItem, "instructions")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbIns" runat="server" Text='<%# Bind( "instructions") %>' width="100%" TabIndex="1" TextMode="MultiLine" Rows="4"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="descValidator" Runat="server" Display="Dynamic" ControlToValidate="tbIns" ErrorMessage="* Required Field">
                                </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <HeaderStyle Width="90%" />
                            </rad:GridTemplateColumn>
                            <rad:GridTemplateColumn HeaderText="Sort Order" UniqueName="sortorder" DataField="sortorder">
                                <ItemTemplate>
                                    <%# DataBinder.Eval(Container.DataItem, "sortorder")%>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tbSortOrder" runat="server" Text='<%# Bind( "sortorder") %>' width="30px" TabIndex="2"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="descValidator2" Runat="server" Display="Dynamic" ControlToValidate="tbSortOrder" ErrorMessage="* Required Field">
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Display="Dynamic" ControlToValidate="tbSortOrder" ErrorMessage="Please enter a valid sort order number." ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
                            </EditItemTemplate>
                            </rad:GridTemplateColumn>
                         </Columns>
                            </rad:GridTableView>
                        </DetailTables>
                     
                    <Columns>
                        <rad:GridBoundColumn DataField="cp_id" HeaderText="CP_ID" UniqueName="CP_ID" Visible="false"></rad:GridBoundColumn>
                        <rad:GridBoundColumn DataField="VisitFrequency" HeaderText="VisitFrequency" UniqueName="VisitFrequency" Visible="false"></rad:GridBoundColumn>
                        <rad:GridClientSelectColumn UniqueName="ClientSelectColumnDetail1"></rad:GridClientSelectColumn>
                        <rad:GridTemplateColumn HeaderText="Visit Frequency" UniqueName="VisitFrequency" DataField="VisitFrequency">
                            <ItemTemplate>
                                <%# DataBinder.Eval(Container.DataItem, "VisitFrequency")%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="tbVisit" runat="server" Text='<%# Bind( "VisitFrequency") %>' width="100%" TabIndex="1" ></asp:TextBox>
                                <asp:RequiredFieldValidator ID="descValidator" Runat="server" Display="Dynamic" ControlToValidate="tbVisit" ErrorMessage="* Required Field">
                            </asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <HeaderStyle Width="80%" />
                        </rad:GridTemplateColumn>
                        <rad:GridTemplateColumn HeaderText="Sort Order" UniqueName="Sortorder" DataField="Sortorder">
                            <ItemTemplate>
                                <%# DataBinder.Eval(Container.DataItem, "Sortorder")%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="tbVisitSortOrder" runat="server" Text='<%# Bind( "Sortorder") %>' width="30px" TabIndex="2" Visible="false"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="descValidator2" Runat="server" Display="Dynamic" ControlToValidate="tbVisitSortOrder" ErrorMessage="* Required Field" >
                            </asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" Display="Dynamic" ControlToValidate="tbVisitSortOrder" ErrorMessage="Please enter a valid sort order number." ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
                        </EditItemTemplate>
                        </rad:GridTemplateColumn>               
 
                     </Columns>
                    </rad:GridTableView>
                 </DetailTables>
                  
               <Columns>
                    <rad:GridBoundColumn DataField="cpd_id" HeaderText="CPD_ID" UniqueName="CPD_ID" Visible="False"></rad:GridBoundColumn>
                    <rad:GridBoundColumn DataField="short_desc" HeaderText="short desc" UniqueName="short_desc" Visible="False"></rad:GridBoundColumn>
                    <rad:GridTemplateColumn HeaderText="Diagnosis" UniqueName="short_desc" DataField="short_desc">
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem, "short_desc")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbDiag" runat="server" Text='<%# Bind( "short_desc") %>' Width="95%" TabIndex="1"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="descValidator" Runat="server" Display="Dynamic" ControlToValidate="tbDiag" ErrorMessage="* Required field">
                            </asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <HeaderStyle Width="20%" />
                    </rad:GridTemplateColumn>
                    <rad:GridTemplateColumn HeaderText="Description" UniqueName="long_desc" DataField="long_desc">
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem, "long_desc")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbDesc" runat="server" Text='<%# Bind( "long_desc") %>' Width="95%" TabIndex="2"></asp:TextBox>
                        </EditItemTemplate>
                        <HeaderStyle Width="80%" />
                    </rad:GridTemplateColumn>
                 </Columns>      
            </MasterTableView>
    <ClientSettings EnablePostBackOnRowClick="false">
       <Selecting AllowRowSelect="True"/>
       <ClientEvents />
    </ClientSettings>
     </rad:RadGrid>


Below is the C# code for master grid. 
protected void gridCPDiag_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
{
            if (!e.IsFromDetailTable)
            {
                ClinicalPathway cp = new ClinicalPathway(AgencyId, BranchId);
                DataTable dt = cp.GetClinicalPathwayList();
                gridCPDiag.DataSource = dt.DefaultView;
            }
}
 
protected void gridCPDiag_PreRender(object sender, EventArgs e)
{
            if (gridCPDiag.MasterTableView.IsItemInserted || cpd_id <= 0) return;
 
            int currentPageIndex = gridCPDiag.CurrentPageIndex;
 
            for (int i = 0; i < gridCPDiag.PageCount; i++)
            {
                foreach (GridDataItem item in gridCPDiag.Items)
                {
                    if (cpd_id.Equals(Convert.ToInt32(item["cpd_id"].Text)))
                    {
                        item.Selected = true;
                        currentPageIndex = -1;
                        break;
                    }
                }
 
                if (currentPageIndex.Equals(-1))
                    break;
 
                currentPageIndex++;
                if (currentPageIndex >= gridCPDiag.PageCount)
                    currentPageIndex = 0;
                gridCPDiag.CurrentPageIndex = currentPageIndex;
                gridCPDiag.Rebind();
            }
}
 
protected void gridCPDiag_DetailTableDataBind(object source, Telerik.WebControls.GridDetailTableDataBindEventArgs e)
{
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
            switch (e.DetailTableView.DataMember)
            {
                case "visit":
                    {
                        string CPID = dataItem.GetDataKeyValue("cpd_id").ToString();
                        ClinicalPathway cp = new ClinicalPathway(AgencyId, BranchId);
                        DataTable dt = cp.GetVisitFreqByDiag(Convert.ToInt32(CPID));
                        e.DetailTableView.DataSource = dt.DefaultView;
                        break;
                    }
 
                case "instruction":
                    {
                        string CPDID = dataItem.GetDataKeyValue("cp_id").ToString(); 
                        ClinicalPathway cp = new ClinicalPathway(AgencyId, BranchId);
                        DataTable dt = cp.GetInstructionsByVisitFreq(Convert.ToInt32(CPDID));
                        e.DetailTableView.DataSource = dt.DefaultView;
                        break;
                    }
            }
        }
 
 
protected void gridCPDiag_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
{
            if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Master")
            {
                GridCommandItem diagcommandItem = (GridCommandItem)e.Item;
                LinkButton diagbtnAdd = (LinkButton)diagcommandItem.FindControl("master_btnAdd");
                LinkButton diaglnkPerformInsert = (LinkButton)diagcommandItem.FindControl("master_lnkPerformInsert");
                LinkButton diagbtnEditSelected = (LinkButton)diagcommandItem.FindControl("master_btnEditSelected");
                LinkButton diagbtnUpdateEdited = (LinkButton)diagcommandItem.FindControl("master_btnUpdateEdited");
                LinkButton diagbtnCancel = (LinkButton)diagcommandItem.FindControl("master_btnCancel");
                LinkButton diagbtnDelete = (LinkButton)diagcommandItem.FindControl("master_btnDelete");
                LinkButton diagbtnPrint = (LinkButton)diagcommandItem.FindControl("master_PrintFriendly");
 
                string printurl = "ClinicalPathways/ClinicalPathwaysrpt.aspx";
                diagbtnPrint.Attributes.Add("onclick", "javascript:window.open('" + printurl + "', '', '');");
 
                if (IsMasterExpanded || IsDetailExpanded)
                {
                    diagbtnAdd.Enabled=false;
                    diagbtnEditSelected.Enabled=false;
                    diagbtnDelete.Enabled = false;
                }
 
                if (hdnCommandName.Value == "master_initinsert" || hdnCommandName.Value == "master_editselected")
                {
                    diagbtnAdd.Visible = false;
                    diagbtnEditSelected.Visible = false;
                    diagbtnDelete.Visible = false;
                    diagbtnCancel.Visible = true;
                }
 
                if (hdnCommandName.Value == "master_initinsert")   
                    diaglnkPerformInsert.Visible = true;
 
                if (hdnCommandName.Value == "master_editselected")
                    diagbtnUpdateEdited.Visible = true;
 
                if (hdnCommandName.Value == "master_performinsert" || hdnCommandName.Value == "master_update" || hdnCommandName.Value == "master_cancelall")
                {
                    diagbtnAdd.Visible = true;
                    diagbtnEditSelected.Visible = true;
                    diagbtnDelete.Visible = true;
                    diaglnkPerformInsert.Visible = false;
                    diagbtnUpdateEdited.Visible = false;
                    diagbtnCancel.Visible = false;
                }
            }
 
            if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Detail2")
            {
                GridCommandItem visitcommandItem = (GridCommandItem)e.Item;
                LinkButton visitbtnAdd = (LinkButton)visitcommandItem.FindControl("det2_btnAdd");
                LinkButton visitlnkPerformInsert = (LinkButton)visitcommandItem.FindControl("det2_lnkPerformInsert");
                LinkButton visitbtnEditSelected = (LinkButton)visitcommandItem.FindControl("det2_btnEditSelected");
                LinkButton visitbtnUpdateEdited = (LinkButton)visitcommandItem.FindControl("det2_btnUpdateEdited");
                LinkButton visitbtnCancel = (LinkButton)visitcommandItem.FindControl("det2_btnCancel");
                LinkButton visitbtnDelete = (LinkButton)visitcommandItem.FindControl("det2_btnDelete");
 
                if (IsDetailExpanded)
                {
                    visitbtnAdd.Enabled = false;
                    visitbtnEditSelected.Enabled = false;
                    visitbtnDelete.Enabled = false;
                }
 
                if (hdnCommandName.Value == "det2_initinsert" || hdnCommandName.Value == "det2_editselected")
                {
                    visitbtnAdd.Visible = false;
                    visitbtnEditSelected.Visible = false;
                    visitbtnDelete.Visible = false;                   
                    visitbtnCancel.Visible = true;
                }
 
                if (hdnCommandName.Value == "det2_initinsert")
                    visitlnkPerformInsert.Visible = true;
 
                if (hdnCommandName.Value == "det2_editselected")
                    visitbtnUpdateEdited.Visible = true;      
                     
                if (hdnCommandName.Value == "det2_performinsert" || hdnCommandName.Value == "det2_update" || hdnCommandName.Value == "det2_cancelall")
                {
                    visitbtnAdd.Visible = true;
                    visitbtnEditSelected.Visible = true;
                    visitbtnDelete.Visible = true;
                    visitlnkPerformInsert.Visible = false;
                    visitbtnUpdateEdited.Visible = false;
                    visitbtnCancel.Visible = false;
                }
 
            }
 
            if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Detail3")
            {
                GridCommandItem inscommandItem = (GridCommandItem)e.Item;
                LinkButton insbtnAdd = (LinkButton)inscommandItem.FindControl("det3_btnAdd");
                LinkButton inslnkPerformInsert = (LinkButton)inscommandItem.FindControl("det3_lnkPerformInsert");
                LinkButton insbtnEditSelected = (LinkButton)inscommandItem.FindControl("det3_btnEditSelected");
                LinkButton insbtnUpdateEdited = (LinkButton)inscommandItem.FindControl("det3_btnUpdateEdited");
                LinkButton insbtnCancel = (LinkButton)inscommandItem.FindControl("det3_btnCancel");
                LinkButton insbtnDelete = (LinkButton)inscommandItem.FindControl("det3_btnDelete");
 
 
                if (hdnCommandName.Value == "det3_initinsert" || hdnCommandName.Value == "det3_editselected")
                {
                    insbtnAdd.Visible = false;
                    insbtnEditSelected.Visible = false;
                    insbtnDelete.Visible = false;
                    insbtnCancel.Visible = true;
                }
 
                if (hdnCommandName.Value == "det3_initinsert")
                    inslnkPerformInsert.Visible = true;
 
                if (hdnCommandName.Value == "det3_editselected")
                    insbtnUpdateEdited.Visible = true;
 
                if (hdnCommandName.Value == "det3_performinsert" || hdnCommandName.Value == "det3_update" || hdnCommandName.Value == "det3_cancelall")
                {
                    insbtnAdd.Visible = true;
                    insbtnEditSelected.Visible = true;
                    insbtnDelete.Visible = true;
                    inslnkPerformInsert.Visible = false;
                    insbtnCancel.Visible = false;
                }
            }
        }
 
protected void gridCPDiag_ItemCommand(object sender, GridCommandEventArgs e)
{
          if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                foreach (GridItem item in e.Item.OwnerTableView.Items)
                {
                    if (item.Expanded && item != e.Item)
                    {
                        item.Expanded = false;
                        this.ExpandedStates.Remove(item.ItemIndexHierarchical);
                        this.ClearExpandedChildren(item.ItemIndexHierarchical);
                    }
                }
 
                if (!e.Item.Expanded)
                {
                    this.ExpandedStates[e.Item.ItemIndexHierarchical] = true;
                }
                else
                {
                    this.ExpandedStates.Remove(e.Item.ItemIndexHierarchical);
                    this.ClearExpandedChildren(e.Item.ItemIndexHierarchical);
                }
 
                if (e.Item.OwnerTableView.Name == "Master")
                {
                    GridCommandItem commandItem = (GridCommandItem)gridCPDiag.MasterTableView.GetItems(GridItemType.CommandItem)[0];
                    LinkButton diagbtnAdd = (LinkButton)commandItem.FindControl("master_btnAdd");
                    LinkButton diagbtnEditSelected = (LinkButton)commandItem.FindControl("master_btnEditSelected");
                    LinkButton diagbtnDelete = (LinkButton)commandItem.FindControl("master_btnDelete");
 
                    if (!e.Item.Expanded)
                    {
                        IsMasterExpanded = true;
                        diagbtnAdd.Enabled = false;
                        diagbtnEditSelected.Enabled = false;
                        diagbtnDelete.Enabled = false;
                    }
                    else
                    {
                        IsMasterExpanded = false;
                        diagbtnAdd.Enabled = true;
                        diagbtnEditSelected.Enabled = true;
                        diagbtnDelete.Enabled = true;
                    }
 
                }
 
                if (e.Item.OwnerTableView.Name == "Detail2")
                {
                    int countOfExpandedItems = 0;
 
                    foreach (GridDataItem masterItem in gridCPDiag.MasterTableView.Items)
                    {
                        IsDetailExpanded = false;
                        if (masterItem.Expanded)
                        {
                            GridCommandItem commandItem = (GridCommandItem)masterItem.ChildItem.NestedTableViews[0].GetItems(GridItemType.CommandItem)[0];
                            LinkButton visitbtnAdd = (LinkButton)commandItem.FindControl("det2_btnAdd");
                            LinkButton visitbtnEditSelected = (LinkButton)commandItem.FindControl("det2_btnEditSelected");
                            LinkButton visitbtnDelete = (LinkButton)commandItem.FindControl("det2_btnDelete");
 
                            countOfExpandedItems += 1;
 
                            visitbtnAdd.Enabled = (e.Item.Expanded && countOfExpandedItems == 1);
                            visitbtnEditSelected.Enabled = (e.Item.Expanded && countOfExpandedItems == 1);
                            visitbtnDelete.Enabled = (e.Item.Expanded && countOfExpandedItems == 1);
                            IsDetailExpanded = true;
                        }                       
                    }                   
                }
            }
 
            if (e.Item.OwnerTableView.Name == "Master")
            {
 
                if (e.Item is GridCommandItem)
                {
                    if (e.CommandName == "InitInsert")
                        hdnCommandName.Value = "master_initinsert";
 
                    if (e.CommandName == "PerformInsert")
                        hdnCommandName.Value = "master_performinsert";
 
                    if (e.CommandName == "EditSelected")
                        hdnCommandName.Value = "master_editselected";
 
                    if (e.CommandName == "Update")
                        hdnCommandName.Value = "master_update";
                     
                    if (e.CommandName == "CancelAll")
                        hdnCommandName.Value = "master_cancelall";
 
                    if (e.CommandName == "Delete")
                        hdnCommandName.Value = "master_delete";
                }
 
            }
                         
            if (e.Item.OwnerTableView.Name == "Detail2")
            {
                if (e.Item is GridCommandItem)
                {
                    GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
                    SelectedCPDiag = (int)(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["cpd_id"]);
 
                    if (e.CommandName == "InitInsert")
                    {
                        hdnCommandName.Value = "det2_initinsert";
                        if (!e.Item.Expanded)
                            IsMasterExpanded = true;
                        else
                            IsMasterExpanded = false;
                    }
 
                    if (e.CommandName == "PerformInsert")
                    {
                        hdnCommandName.Value = "det2_performinsert";
 
                        GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();                       
                        if (insertedItem.IsInEditMode)
                        {
                            int cpv_id = 0;
                            cpv_id = InsertVisitFreq(insertedItem);
                            e.Item.OwnerTableView.Rebind();
                        }
                    }
 
                    if (e.CommandName == "EditSelected")
                    {
                        hdnCommandName.Value = "det2_editselected";
                        if (!e.Item.Expanded)
                            IsMasterExpanded = true;
                        else
                            IsMasterExpanded = false;
                    }
 
                    if (e.CommandName == "Update")
                    {
                        hdnCommandName.Value = "det2_update";
 
                        GridTableView table = (GridTableView)e.Item.OwnerTableView;
                        foreach (GridEditableItem editItem in table.GetItems(GridItemType.EditItem))
                        {
                            string cpid = editItem.GetDataKeyValue("cp_id").ToString();
                            TextBox txtVisitFreq = (TextBox)editItem.FindControl("tbVisit");
                            TextBox txtVisitSortOrder = (TextBox)editItem.FindControl("tbVisitSortOrder");
 
                            UpdateVisitFreq(cpid, txtVisitFreq.Text, Convert.ToInt32(txtVisitSortOrder.Text));
                            editItem.Edit = false;
                        }
                    }
                     
                    if (e.CommandName == "CancelAll")
                    {
                        hdnCommandName.Value = "det2_cancelall";
 
                    }
 
                    if (e.CommandName == "Delete")
                    {
                        hdnCommandName.Value = "det2_delete";
 
                        GridTableView table = (GridTableView)e.Item.OwnerTableView;
                        foreach (GridDataItem childitem in table.Items)
                        {
                            if (childitem.Selected)
                            {
                                int cpid = Convert.ToInt32(childitem.GetDataKeyValue("cp_id"));
                                string desc = childitem.Cells[3].Text;
                                DeleteVisitFreq(cpid, desc);
                            }
                        }
                        table.Rebind();
                    }
                }
 
            }
 
            if (e.Item.OwnerTableView.Name == "Detail3")
            {
                 
                    GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
                    SelectedCPVisitFreq = (int)(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["cp_id"]);
 
                    if (e.CommandName == "InitInsert")
                    {
                        hdnCommandName.Value = "det3_initinsert";
                        if (!e.Item.Expanded)
                            IsDetailExpanded = true;
                        else
                            IsDetailExpanded = false;
                    }
 
                    if (e.CommandName == "PerformInsert")
                    {
                        hdnCommandName.Value = "det3_performinsert";
 
                        GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
                        if (insertedItem.IsInEditMode)
                        {
                            int cpi_id = 0;
                            cpi_id = InsertVFIns(insertedItem);
                            e.Canceled = true;
                            e.Item.OwnerTableView.Rebind();
                        }
                    }
 
                    if (e.CommandName == "EditSelected")
                    {
                        hdnCommandName.Value = "det3_editselected";
                        if (!e.Item.Expanded)
                            IsDetailExpanded = true;
                        else
                            IsDetailExpanded = false;
                    }
 
                    if (e.CommandName == "Update")
                    {
                        hdnCommandName.Value = "det3_update";
 
                        GridTableView table = (GridTableView)e.Item.OwnerTableView;
                        foreach (GridEditableItem editItem in table.GetItems(GridItemType.EditItem))
                        {
                            string cpiid = editItem.GetDataKeyValue("cpi_id").ToString();
                            TextBox txtInstr = (TextBox)editItem.FindControl("tbIns");
                            TextBox txtSortOrder = (TextBox)editItem.FindControl("tbSortOrder");
 
                            UpdateVFIns(cpiid, txtInstr.Text, Convert.ToInt32(txtSortOrder.Text));
                            editItem.Edit = false;
                        }
                    }
 
                    if (e.CommandName == "CancelAll")
                    {
                        hdnCommandName.Value = "det3_cancelall";
                    }
 
                    if (e.CommandName == "Delete")
                    {
                        hdnCommandName.Value = "det3_delete";
 
                        GridTableView table = (GridTableView)e.Item.OwnerTableView;
                        foreach (GridDataItem childitem in table.Items)
                        {
                            if (childitem.Selected)
                            {
                                int cpid = Convert.ToInt32(childitem.GetDataKeyValue("cpi_id"));
                                string desc = childitem.Cells[2].Text;
                                DeleteVFIns(cpid, desc);
                            }
                        }
                        table.Rebind();
                    }
                }           
        }

I would really appreciate for any response.

Thanks!
Zel

2 Answers, 1 is accepted

Sort by
0
zel
Top achievements
Rank 1
answered on 08 Oct 2010, 08:31 AM
Hello Telerik Support Team,

I haven't receive any response with regards to my problem. I know that there is something missing or wrong in my code. but I can't figure it out where did it occur.

Please help.

Thanks!
Zel
0
Accepted
Maria Ilieva
Telerik team
answered on 08 Oct 2010, 11:15 AM
Hello ,

Please refer to the following forum post and verify if the provided solutions work for you.
http://www.telerik.com/community/forums/aspnet-ajax/grid/hierarchical-grid-prevent-double-inserting-editing.aspx

Sincerely yours,
Maria Ilieva
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
zel
Top achievements
Rank 1
Answers by
zel
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or