Child stays in editmode after insert

3 posts, 1 answers
  1. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 17 Mar 2011 Link to this post

    I have a rad grid that I have set the AllowAutomaticDeletes, Updates, and Inserts to False. This in the MsterTableView has a DetailTable.  So it is Hierarchy gid.  The top level works fine when I Insert or Update the grid comes out of editmode, and when I edit the DetailTable grid it will leave edit mode with no issue.  The problem is when I insert a new record in the DetailTable on save it stays in edit mode.  The data is saveed becuase when I hit the cancel button it shows the new record under the parent.

    I'm I missing something

    <telerik:RadGrid ID="rgSoftware" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="false"
            AllowSorting="false" GridLines="Both" AllowPaging="false" EnableViewState="true" Skin="WebBlue" 
            ShowHeader="true" EnableAJAXLoadingTemplate="True" LoadingTemplateTransparency="50" ShowStatusBar="True" 
            AllowAutomaticDeletes="false" AllowAutomaticUpdates="False" AllowAutomaticInserts="False"        
            OnNeedDataSource="rgSoftware_NeedDataSource" OnInsertCommand="rgSoftware_InsertCommand" OnUpdateCommand="rgSoftware_UpdateCommand"
            OnDetailTableDataBind="rgSoftware_DetailTableDataBind" OnItemCommand="rgSoftware_ItemCommand" OnDataBound="rgSoftware_DataBound">
            <MasterTableView Font-Names="Helvetica, Arial, Verdana, sans-serif" Font-Size="10px"
                DataKeyNames="SoftwareID" Name="SoftwareGroup" Width="100%" runat="server" EditMode="InPlace"
                CommandItemDisplay="Top">
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="LicenseInfoID" Name="LicenseInfoID" Width="100%"
                        runat="server" Font-Size="10px" EditMode="InPlace" CommandItemDisplay="Top" AllowAutomaticInserts="true"
                        AllowAutomaticUpdates="true">
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~/Images/Grid/Save.gif"
                                EditImageUrl="~/Images/Grid/Edit.gif" InsertImageUrl="~/Images/Grid/Save.gif"
                                CancelImageUrl="~/Images/Grid/Cancel.gif" />
                            <telerik:GridBoundColumn DataField="LicenseInfoID" Visible="false" />
                            <telerik:GridTemplateColumn HeaderText="Key" UniqueName="Key">
                                <ItemTemplate>
                                    <asp:Label ID="lblKey" runat="server" Text='<%# Eval("LicenseKey")%>' />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="tbKey" runat="server" Text='<%# Eval("LicenseKey")%>' Width="200px"
                                        Font-Size="10px" />
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="# of Licenses" UniqueName="Qty">
                                <ItemTemplate>
                                    <asp:Label ID="lblQty" runat="server" Text='<%# Eval("NumberOfLicenses")%>' />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadNumericTextBox ID="tbQty" runat="server" text='<%# Eval("NumberOfLicenses")%>'
                                        Width="30px" NumberFormat-DecimalDigits="0" ShowSpinButtons="false" Font-Size="10px" />
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridCheckBoxColumn UniqueName="chkActive" DataField="Active" HeaderText="Active" />
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~/Images/Grid/Save.gif"
                        EditImageUrl="~/Images/Grid/Edit.gif" InsertImageUrl="~/Images/Grid/Save.gif"
                        CancelImageUrl="~/Images/Grid/Cancel.gif" />
                    <telerik:GridBoundColumn DataField="SoftwareID" Visible="false" />
                    <telerik:GridTemplateColumn HeaderText="Software" UniqueName="SoftwareName">
                        <ItemTemplate>
                            <asp:Label ID="lblSoftwareName" runat="server" Text='<%# Eval("SoftwareName")%>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="tbSoftwareName" runat="server" Text='<%# Eval("SoftwareName")%>'
                                Width="250px" Font-Size="10px" />                        
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="Location" UniqueName="LocationOfSoftware">
                        <ItemTemplate>
                            <asp:Label ID="lblLocationOfSoftware" runat="server" Text='<%# Eval("LocationOfSoftware")%>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="tbLocationOfSoftware" runat="server" Text='<%# Eval("LocationOfSoftware")%>'
                                Width="250px" Font-Size="10px" />                        
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridCheckBoxColumn HeaderText="Active" DataField="Active" UniqueName="SoftwareActive" />
                </Columns>
            </MasterTableView>
            <ClientSettings AllowRowsDragDrop="true">
            </ClientSettings>
            <FilterMenu EnableEmbeddedSkins="False">
            </FilterMenu>
        </telerik:RadGrid>




    protected void rgSoftware_InsertCommand(object source, GridCommandEventArgs e)
           {
               AssetDataDataContext db = new AssetDataDataContext();
               GridEditableItem editedItem = e.Item as GridEditableItem;
               if ("SoftwareGroup".Equals(e.Item.OwnerTableView.Name))
               {                
                   Software nSoftware = new Software();
                   SaveSoftwareGroup(nSoftware, editedItem);
                   db.Softwares.InsertOnSubmit(nSoftware);                
               }
               else if ("LicenseInfoID".Equals(e.Item.OwnerTableView.Name))
               {
                   GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem;
                   LicenseInfo nLicense = new LicenseInfo();
                                  
                   nLicense.SoftwareID = Int32.Parse(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["SoftwareID"].ToString());
                   SaveLicenseInfo(nLicense, editedItem);                
                   db.LicenseInfos.InsertOnSubmit(nLicense);
               }
               db.SubmitChanges();
                 
           }
           protected void rgSoftware_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
           {
               AssetDataDataContext db = new AssetDataDataContext();
               GridEditableItem editedItem = e.Item as GridEditableItem;
               if ("SoftwareGroup".Equals(e.Item.OwnerTableView.Name))
               {                
                   Int32 SoftwareID = Int32.Parse(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["SoftwareID"].ToString());                
                   Software nSoftware = db.Softwares.SingleOrDefault(s => s.SoftwareID == SoftwareID);
                   SaveSoftwareGroup(nSoftware, editedItem);
               }
               else if ("LicenseInfoID".Equals(e.Item.OwnerTableView.Name))
               {
                   //Get the primary key value using the DataKeyValue.     
                   Int32 LicenseInfoID = Int32.Parse(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["LicenseInfoID"].ToString());
                   LicenseInfo nLicense = db.LicenseInfos.SingleOrDefault(l => l.LicenseInfoID == LicenseInfoID);
                   SaveLicenseInfo(nLicense, editedItem);   
               }
               db.SubmitChanges();
               rgSoftware.MasterTableView.ClearEditItems();
           }
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Mar 2011 Link to this post

    Hello Eric,

    This issue is occurring because you have set the AllowAutomaticInserts and AllowAutomaticUpdates property of Detail TableView as 'True'. You can set this when you are performing automatic data source operations. The automatic data source operations only work when binding the grid (here DetailTable) to a declarative data source using DataSourceID property of the grid.

    Hope this helps,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 18 Mar 2011 Link to this post

    Thanks Princy I wasn't even looking there. 
Back to Top