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

Insert into detail table section in Hierarchical Radgrid by clicking the button placed outside.

13 Answers 462 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Puay Chai Tan
Top achievements
Rank 1
Puay Chai Tan asked on 30 Jul 2010, 06:02 AM
Hi,

how to  Insert into detail table section in Hierarchical Radgrid by clicking the button placed outside.

13 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 30 Jul 2010, 06:28 AM
Hello,

I am not sure of your requirement. If you are trying to access the DetailTable, then the following help articles will help you in this.

Traversing detail tables/items in Telerik RadGrid
Distinguish grid rows in hierarchy on ItemCreated/ItemDataBound

Could you elaborate your scenario if this doesn't help you?

Thanks,
Princy.
0
zel
Top achievements
Rank 1
answered on 08 Sep 2010, 07:39 AM
Hi,

I have the same problem with Tan. The radgrid has 3 hierarchies, and each hierarchy has a custom command item for Add,Edit and Delete. My problem is, how to handle the event of linkbutton inside the detail table (GridTableView Name Detail2 and 3)?

Below is my aspx 

<rad:RadGrid runat="server" ID="gridCPDiag" AllowPaging="True"  AllowSorting="True"  PageSize="15"
            AutoGenerateColumns="False" GridLines="None" BorderStyle="None" Skin="Outlook"
            OnNeedDataSource="gridCPDiag_NeedDataSource"
            OnDetailTableDataBind="gridCPDiag_DetailTableDataBind"
            OnInsertCommand="gridCPDiag_InsertCommand"
            OnUpdateCommand="gridCPDiag_UpdateCommand"
            OnDeleteCommand="gridCPDiag_DeleteCommand"
            OnPreRender="gridCPDiag_PreRender" OnItemDataBound="gridCPDiag_ItemDataBound">
            <MasterTableView 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="btnAdd" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="InitInsert" Visible='<%# !gridCPDiag.MasterTableView.IsItemInserted && gridCPDiag.EditIndexes.Count == 0 %>'><img style="border:0px" alt="" src="../images/addemail.gif" /> Add</asp:LinkButton>
                                                <asp:LinkButton ID="lnkPerformInsert" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="PerformInsert" Visible='<%# gridCPDiag.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                            </td>
                                            <td>
                                                <div class="toolbarIconDivider">|</div>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="btnEditSelected"  CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="EditSelected" Visible='<%# !gridCPDiag.MasterTableView.IsItemInserted && gridCPDiag.EditIndexes.Count == 0 %>'><img style="border:0px" alt="" src="../images/edit.gif" /> Edit</asp:LinkButton>
                                                <asp:LinkButton ID="btnUpdateEdited" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Update" Visible='<%# gridCPDiag.EditIndexes.Count > 0 %>'><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                <asp:LinkButton ID="btnCancel" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="CancelAll" Visible='<%# gridCPDiag.EditIndexes.Count > 0 || gridCPDiag.MasterTableView.IsItemInserted %>' 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="btnDelete" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Delete" Visible='<%# !gridCPDiag.MasterTableView.IsItemInserted && gridCPDiag.EditIndexes.Count == 0 %>' 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>
                                        </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="btnAdd" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="InitInsert" Visible="false"><img style="border:0px" alt="" src="../images/addemail.gif" /> Add</asp:LinkButton>
                                                    <asp:LinkButton ID="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="btnEditSelected"  CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="EditSelected" Visible="false"><img style="border:0px" alt="" src="../images/edit.gif" /> Edit</asp:LinkButton>
                                                    <asp:LinkButton ID="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="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="btnDelete" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Delete" Visible="false" 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>                   
                        <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="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="lnkPerformInsert" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="PerformInsert"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                </td>
                                                <td>
                                                    <div class="toolbarIconDivider">|</div>
                                                </td>
                                                <td>
                                                    <asp:LinkButton ID="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="btnUpdateEdited" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="Update"><img style="border:0px" alt="" src="../images/save.gif" /> Save</asp:LinkButton>
                                                    <asp:LinkButton ID="btnCancel" CssClass="mu" onmouseover="this.className='mo'" onmouseout="this.className='mu'" runat="server" CommandName="CancelAll"  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="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>
                        </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:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                            <HeaderTemplate>
                             <asp:CheckBox id="headerChkbox"  AutoPostBack="True" runat="server"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="chkSelect"  AutoPostBack="True" runat="server"></asp:CheckBox>
                            </ItemTemplate>
                             <HeaderStyle Width="2%" />
                        </rad:GridTemplateColumn>
                        <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"></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"/>
    </ClientSettings>
     </rad:RadGrid>

I would really appreciate for any quick response.

Thanks,
Lyzel

0
Princy
Top achievements
Rank 1
answered on 08 Sep 2010, 10:19 AM
Hello Lyzel,

The RadGrid.ItemCommand event will be fired when a custom command bubbles from the CommandItem, which lets you define custom functionality that can be executed in the ItemCommand handler. And you can check with the name of OwnerTableView to identify the operaion for MasterTable/DetailTables.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == "InitInsert" && e.Item.OwnerTableView.Name == "Master")
            //for Add Button in MasterTableView
       {
 
       }
 
       if (e.CommandName == "InitInsert" && e.Item.OwnerTableView.Name == "Detail2")
           //for Add Button in Detail2
       {
 
       }
       if (e.CommandName == "InitInsert" && e.Item.OwnerTableView.Name == "Detail3")
          //for Add Button in Detail3
       {
 
       }
   }

Thanks,
Princy.
0
zel
Top achievements
Rank 1
answered on 09 Sep 2010, 10:00 AM
Hi Princy,

Thanks for your reply. But I have another problem, how to show/hide some link buttons after clicking the Add or Edit? Even though i set the property of link button to true, it will not appear in the command item. 

Kindly check my code below.
protected void gridCPDiag_ItemCommand(object sender, GridCommandEventArgs e)
   {
       
       if (e.Item.OwnerTableView.Name == "Detail2")
       {
           if (e.Item is GridCommandItem)
           {
               GridCommandItem commandItem = e.Item as GridCommandItem;
               LinkButton btnAdd = commandItem.FindControl("btnAdd") as LinkButton;
               LinkButton lnkPerformInsert =  commandItem.FindControl("lnkPerformInsert") as LinkButton;
               LinkButton btnEditSelected =  commandItem.FindControl("btnEditSelected") as LinkButton;
               LinkButton btnUpdateEdited =  commandItem.FindControl("btnUpdateEdited") as LinkButton;
               LinkButton btnCancel =  commandItem.FindControl("btnCancel") as LinkButton;
               LinkButton btnDelete = commandItem.FindControl("btnDelete") as LinkButton;
 
               btnAdd.Visible = false;
               btnEditSelected.Visible = false;
               btnDelete.Visible = false;
 
               if (e.CommandName == "InitInsert")
               {
                   lnkPerformInsert.Visible = true;
                   btnCancel.Visible = true;
               }
 
               if (e.CommandName == "EditSelected")
               {
                   btnUpdateEdited.Visible = true;
                   btnCancel.Visible = true;
               }
           }
 
           
       }
   }

Thanks!
Lyzel
0
Princy
Top achievements
Rank 1
answered on 09 Sep 2010, 12:22 PM
Hello Lyzel,

You can try this in ItemDataBound event. In ItemCommand event you can identify which operation is performing and store the opeartion name in a hiddenField .Then in ItemDataBound event based on this HiddenField value, hide the corresponding controls. Check out the sample code.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
      if(e.Item.OwnerTableView.Name == "Detail2")
       {
        if (e.CommandName == "InitInsert")
         {
            HiddenField1.Value = "InitInsert";
         }
        else if(e.CommandName == "EditSelected")
        {
            HiddenField1.Value = "EditSelected";
        }
       . . . . . .. . . . . . . . . . . . . . . .
   }
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Detail2")
        {
            GridCommandItem commandItem = (GridCommandItem)e.Item;
            LinkButton lnkPerformInsert = commandItem.FindControl("lnkPerformInsert") as LinkButton;
            LinkButton btnEditSelected = commandItem.FindControl("btnEditSelected") as LinkButton;
            LinkButton btnUpdateEdited = commandItem.FindControl("btnUpdateEdited") as LinkButton;
            LinkButton btnCancel = commandItem.FindControl("btnCancel") as LinkButton;
            LinkButton btnDelete = commandItem.FindControl("btnDelete") as LinkButton;
 
            if (HiddenField1.Value == "InitInsert")
            {
 
                lnkPerformInsert.Visible = true;
                btnEditSelected.Visible = false;
                btnUpdateEdited.Visible = false;
                btnCancel.Visible = true;
                btnDelete.Visible = false;
            }
            else if (HiddenField1.Value == "EditSelected")
            {
                lnkPerformInsert.Visible = false;
                btnEditSelected.Visible = false;
                btnUpdateEdited.Visible = true;
                btnCancel.Visible = true;
                btnDelete.Visible = false;
            }
            else
            {
                lnkPerformInsert.Visible = true;
                btnEditSelected.Visible = true;
                btnUpdateEdited.Visible = true;
                btnCancel.Visible = true;
                btnDelete.Visible =  true;
            }
        }
    }

Thanks,
Princy.
0
zel
Top achievements
Rank 1
answered on 13 Sep 2010, 09:49 AM
Hi Princy,

I really appreciate your quick response. The sample code you provided is working. But, I have another problems

  1. how to find the edit itemtemplate control inside the detail table? I want to show the tbVisitSortOrder textbox when clicking the edit link button.
<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:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                            <HeaderTemplate>
                             <asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState"  AutoPostBack="True" runat="server"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="chkSelect" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </ItemTemplate>
                             <HeaderStyle Width="2%" />
                        </rad:GridTemplateColumn>
                        <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>

  1. Upon clicking the cancel button from detail table, the detail grid and parent grid will collapsed. how to save the state of parent table as expanded?
  2. how to select the row of newly added data or currently edited data in detail table? 
  3. how to rebind the Detail3 detail table after adding new data? in master_itemcommand event, i added the code to insert the new data. please check my code below. 

                    if (e.CommandName == "PerformInsert")
                    {
                        CommandState = "performinsert";

                        GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();                        
                        if (insertedItem.IsInEditMode)
                        {
                            InsertVFIns(insertedItem);
                            e.Item.OwnerTableView.Rebind();
                        }
                    }

private void InsertVFIns(GridEditableItem insertItem)
            {
                TextBox txtInstr = (TextBox)insertItem.FindControl("tbIns");
                TextBox txtSortOrder = (TextBox)insertItem.FindControl("tbSortOrder");

                ClinicalPathway cp = new ClinicalPathway(AgencyId, BranchId);
                char mode = 'i';
                cp.UpdateVisitInstruction(-1, SelectedCPVisitFreq, txtInstr.Text, Convert.ToInt32(txtSortOrder.Text), mode);

                insertItem.Edit = false;
            } The data was successfully added to the database, but an error will occur "Insert item is available only when grid is in insert mode."
protected void Master_InsertCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
       {           

              GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();

            if (insertedItem.IsInEditMode)
           {
               cpd_id = InsertCPDiag(insertedItem);
               gridCPDiag.Rebind();
 
           }
       }

Thanks a lot Princy!
Lyzel

0
zel
Top achievements
Rank 1
answered on 21 Sep 2010, 03:48 AM
Telerik Support,

Please help me with my last problem. I am not getting any answer from your team anymore. 

I would really appreciate for any response.

Thanks,
Lyzel
0
Mira
Telerik team
answered on 24 Sep 2010, 08:13 AM
Hello Zel,

Straight to your questions:
  1. Please take a look at the Referencing controls in grid row/edit form help topic to see how to find the desired control.
  2. You can use the approach from the Retain expanded/selected state in hierarchy on rebind code library.
  3. Please examine the Select Last Inserted Row in the RadGrid with both Paging and Sorting enabled code library to see how this functionality can be achieved.
  4. Please check the Inserting values in-place and EditForms help topic to learn the proper ways to insert grid rows with InPlace and EditForms edit mode.

I hope this helps.

Greetings,
Mira
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
zel
Top achievements
Rank 1
answered on 24 Sep 2010, 10:31 AM

Hello Everyone,

I already tried the code in Retain expanded/selected state in hierarchy on rebind. But I have a problem, every time I click on edit command item in detail 3 the other command item for detail 2 and master table also changes.


Please see the attached screenshots Before and After clicking the edit command item in detail 3.

Below is my C# code for customizing the visibility of command items.

protected void gridCPDiag_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
       {
           if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Detail2")
           {
               GridCommandItem visitcommandItem = (GridCommandItem)e.Item;
               LinkButton visitbtnAdd = (LinkButton)visitcommandItem.FindControl("btnAdd");
               LinkButton visitlnkPerformInsert = (LinkButton)visitcommandItem.FindControl("lnkPerformInsert");
               LinkButton visitbtnEditSelected = (LinkButton)visitcommandItem.FindControl("btnEditSelected");
               LinkButton visitbtnUpdateEdited = (LinkButton)visitcommandItem.FindControl("btnUpdateEdited");
               LinkButton visitbtnCancel = (LinkButton)visitcommandItem.FindControl("btnCancel");
               LinkButton visitbtnDelete = (LinkButton)visitcommandItem.FindControl("btnDelete");
                
 
               if (CommandState == "initinsert" || CommandState == "editselected")
               {
                   visitbtnAdd.Visible = false;
                   visitbtnEditSelected.Visible = false;
                   visitbtnDelete.Visible = false;                   
                   visitbtnCancel.Visible = true;
               }
 
               if (CommandState == "initinsert")
               {
                   visitlnkPerformInsert.Visible = true;
               }
               if (CommandState == "editselected")
               {
                   visitbtnUpdateEdited.Visible = true;
                    
               }
 
               if (CommandState == "performinsert" || CommandState == "update" || CommandState == "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("btnAdd");
               LinkButton inslnkPerformInsert = (LinkButton)inscommandItem.FindControl("lnkPerformInsert");
               LinkButton insbtnEditSelected = (LinkButton)inscommandItem.FindControl("btnEditSelected");
               LinkButton insbtnUpdateEdited = (LinkButton)inscommandItem.FindControl("btnUpdateEdited");
               LinkButton insbtnCancel = (LinkButton)inscommandItem.FindControl("btnCancel");
               LinkButton insbtnDelete = (LinkButton)inscommandItem.FindControl("btnDelete");
 
 
               if (CommandState == "initinsert" || CommandState == "editselected")
               {
                   insbtnAdd.Visible = false;
                   insbtnEditSelected.Visible = false;
                   insbtnDelete.Visible = false;
                   insbtnCancel.Visible = true;
               }
 
               if (CommandState == "initinsert")
               {
                   inslnkPerformInsert.Visible = true;
               }
               if (CommandState == "editselected")
               {
                   insbtnUpdateEdited.Visible = true;
 
               }
 
               if (CommandState == "performinsert" || CommandState == "update" || CommandState == "cancelall")
               {
                   insbtnAdd.Visible = true;
                   insbtnEditSelected.Visible = true;
                   insbtnDelete.Visible = true;
                   inslnkPerformInsert.Visible = false;
                   insbtnCancel.Visible = false;
               }
           }
       }



Please help.

Thanks!
Lyzel

0
zel
Top achievements
Rank 1
answered on 27 Sep 2010, 03:53 AM
Hello Everyone!

Please help me with my problem that i posted last 2 days ago. I really have no idea, why is the command items for master table and detail table 2 changes, every time i click on edit in detail table 3.

Below is the code that I have added to retain expanded/selected in hierarchy.

private Hashtable _ordersExpandedState;
private Hashtable _selectedState;
 
protected void Page_Load(object sender, EventArgs e)
{
            Ajax.Utility.RegisterTypeForAjax(typeof(ClinicalPathwaySetup));
 
            if (!IsPostBack)
            {
                this._ordersExpandedState = null;
                this.Session["_ordersExpandedState"] = null;
            }           
        }
 
 protected void gridCPDiag_Databound(object sender, EventArgs e)
        {
            //Expand all items using our custom storage
            string[] indexes = new string[this.ExpandedStates.Keys.Count];
            this.ExpandedStates.Keys.CopyTo(indexes, 0);
 
            ArrayList arr = new ArrayList(indexes);
            //Sort so we can guarantee that a parent item is expanded before any of
            //its children
            arr.Sort();
 
            foreach (string key in arr)
            {
                bool value = (bool)this.ExpandedStates[key];
                if (value)
                {
                    gridCPDiag.Items[key].Expanded = true;
                }
            }
 
            //Select all items using our custom storage
            indexes = new string[this.SelectedStates.Keys.Count];
            this.SelectedStates.Keys.CopyTo(indexes, 0);
 
            arr = new ArrayList(indexes);
            //Sort to ensure that a parent item is selected before any of its children
            arr.Sort();
 
            foreach (string key in arr)
            {
                bool value = (bool)this.SelectedStates[key];
                if (value)
                {
                    gridCPDiag.Items[key].Selected = true;
                }
            }
        }
 
//Save/load expanded states Hash from the session
        //this can also be implemented in the ViewState
        private Hashtable ExpandedStates
        {
            get
            {
                if (this._ordersExpandedState == null)
                {
                    _ordersExpandedState = this.Session["_ordersExpandedState"] as Hashtable;
                    if (_ordersExpandedState == null)
                    {
                        _ordersExpandedState = new Hashtable();
                        this.Session["_ordersExpandedState"] = _ordersExpandedState;
                    }
                }
 
                return this._ordersExpandedState;
            }
        }
        //Clear the state for all expanded children if a parent item is collapsed
        private void ClearExpandedChildren(string parentHierarchicalIndex)
        {
            string[] indexes = new string[this.ExpandedStates.Keys.Count];
            this.ExpandedStates.Keys.CopyTo(indexes, 0);
            foreach (string index in indexes)
            {
                //all indexes of child items
                if (index.StartsWith(parentHierarchicalIndex + "_") ||
                    index.StartsWith(parentHierarchicalIndex + ":"))
                {
                    this.ExpandedStates.Remove(index);
                }
            }
        }
        //Save/load selected states Hash from the session
        //this can also be implemented in the ViewState
        private Hashtable SelectedStates
        {
            get
            {
                if (this._selectedState == null)
                {
                    _selectedState = this.Session["_selectedState"] as Hashtable;
                    if (_selectedState == null)
                    {
                        _selectedState = new Hashtable();
                        this.Session["_selectedState"] = _selectedState;
                    }
                }
 
                return this._selectedState;
            }
        }


Thanks!
Zel
0
Mira
Telerik team
answered on 29 Sep 2010, 09:09 AM
Hello Zel,

I looked through your code and I cannot see an obvious reason for the described issue.
Please send us a small working project, demonstrating your full setup and showing the unwanted behavior.
We will debug it locally and get back to you.

Thank you in advance for the cooperation.

Kind regards,
Mira
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
zel
Top achievements
Rank 1
answered on 29 Sep 2010, 09:14 AM
Hi Mira,

Please disregard my problem. I already figured it out why are the command items in master table changes, every time i click on edit in any detail table.

I forgot to mention that I have set the visibility of command items in master table in aspx. 

Thanks for replying.
Zel
0
Bryan
Top achievements
Rank 2
answered on 12 Mar 2013, 12:45 PM
*nevermind, I created a new thread.
Tags
Grid
Asked by
Puay Chai Tan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
zel
Top achievements
Rank 1
Mira
Telerik team
Bryan
Top achievements
Rank 2
Share this question
or