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

AllowAutomaticUpdates doesn't work with user control edit form?

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kelly
Top achievements
Rank 1
Kelly asked on 27 Jan 2009, 09:03 PM
Why doesn't AllowAutomaticUpdate/AllowAutomaticInserts work when I'm using a user control as my edit form?

Insert/update works great if I comment out my EditFormType="WebUserControl" settings and I'm using the built-in EditForms or InPlace editing mode.  But when I add my user control settings in the EditFormSettings and try to update a row, my changes aren't saved at all.  No error - it just doesn't save the changes I make in the form.  I have other pages using user controls as the edit form but they use InsertCommand and UpdateCommand events instead of AllowAutomaticUpdate/AllowAutomaticInserts - do I need to do the same thing here and if so, why? 

Here's my grid code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PurchaseOrders.ascx.cs" 
    Inherits="AdminWebsite.Admin.UserControls.Projects.PurchaseOrders.PurchaseOrders" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<%@ Reference Control="~/Admin/UserControls/Projects/PurchaseOrders/PurchaseOrderForm.ascx" %> 
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="PurchaseOrderDataSource" 
    AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true"
    <MasterTableView DataKeyNames="PurchaseOrderID" EditMode="EditForms" CommandItemDisplay="Top" 
        AutoGenerateColumns="false"
        <EditFormSettings EditFormType="WebUserControl" UserControlName="~/Admin/UserControls/Projects/PurchaseOrders/PurchaseOrderForm.ascx"
        </EditFormSettings> 
        <CommandItemTemplate> 
             <asp:LinkButton ID="NewCommissionButton" runat="server" CommandName="InitInsert"
                <img class="middle" alt="" src="../Images/Telerik/AddRecord.gif" /> Add New Purchase Order&nbsp; 
                    </asp:LinkButton> 
        </CommandItemTemplate> 
        <Columns> 
            <telerik:GridButtonColumn CommandName="Delete" Text="Remove" UniqueName="DeleteColumn" 
                ImageUrl="~/Images/Telerik/delete.gif" ConfirmText="Are you sure you want to delete this purchase order?" 
                ButtonType="ImageButton"
                <HeaderStyle Width="5%" /> 
                <ItemStyle HorizontalAlign="Center" /> 
            </telerik:GridButtonColumn> 
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="~/Images/Telerik/Update.gif" 
                EditImageUrl="~/Images/Telerik/Edit.gif" InsertImageUrl="~/Images/Telerik/update.gif" 
                CancelImageUrl="~/Images/Telerik/Cancel.gif" UniqueName="EditCommandColumn"
                <HeaderStyle Width="5%" /> 
                <ItemStyle HorizontalAlign="Center" /> 
            </telerik:GridEditCommandColumn> 
            <telerik:GridBoundColumn DataField="PurchaseOrderID" HeaderText="Purchase Order ID"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="PONumber" HeaderText="Purchase Order #"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="Date" HeaderText="Date" DataFormatString="{0:M/d/yyyy}"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="ShipTo" HeaderText="ShipTo"
            </telerik:GridBoundColumn> 
        </Columns> 
    </mastertableview> 
    <clientsettings> 
        <ClientEvents OnPopUpShowing="CenterPopup" /> 
    </clientsettings> 
</telerik:RadGrid> 
<asp:LinqDataSource ID="PurchaseOrderDataSource" runat="server" ContextTypeName="NewMillennium.DataAccess.Linq.Projects.ProjectsDataContext" 
    TableName="PurchaseOrders" Where="ProjectProgram.ProjectProgramID == @ProjectProgramID" 
    EnableDelete="true" EnableInsert="true" EnableUpdate="true"
    <WhereParameters> 
        <asp:QueryStringParameter Name="ProjectProgramID" QueryStringField="ProjectProgramID" 
            Type="Int32" /> 
    </WhereParameters> 
    <InsertParameters> 
        <asp:QueryStringParameter Name="ProjectProgramID" QueryStringField="ProjectProgramID" 
            Type="Int32" /> 
        <asp:Parameter Name="PurchaseOrderID" /> 
        <asp:Parameter Name="PublisherID" /> 
        <asp:Parameter Name="ShipTo" /> 
    </InsertParameters> 
    <UpdateParameters> 
        <asp:QueryStringParameter Name="ProjectProgramID" QueryStringField="ProjectProgramID" 
            Type="Int32" /> 
        <asp:Parameter Name="PurchaseOrderID" /> 
        <asp:Parameter Name="PublisherID" /> 
        <asp:Parameter Name="ShipTo" /> 
    </UpdateParameters> 
    <DeleteParameters> 
        <asp:Parameter Name="PurchaseOrderID" /> 
    </DeleteParameters> 
</asp:LinqDataSource> 
 

Here's my user control code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PurchaseOrderForm.ascx.cs" 
    Inherits="AdminWebsite.Admin.UserControls.Projects.PurchaseOrders.PurchaseOrderForm" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<div class="padding8"
    <table style="width: 100%" border="0" cellpadding="4" cellspacing="8"
        <tr> 
            <th class="lightgray label"
                Vendor 
            </th> 
            <th class="lightgray label"
                Ship To 
            </th> 
        </tr> 
        <tr> 
            <td class="toppadding5"
                <telerik:RadComboBox ID="drdPublisher" runat="server" DataSourceID="PublisherDataSource" 
                    DataValueField="PublisherID" DataTextField="PublisherName" MarkFirstMatch="true" 
                    Height="400px" Width="320px" ShowToggleImage="True" Skin="MillenniumAdmin" EnableEmbeddedSkins="false" 
                    AppendDataBoundItems="true" SelectedValue='<%# Bind("PublisherID") %>' Style="z-index: 99999999"
                    <items> 
                        <telerik:RadComboBoxItem Value="" Text="" /> 
                    </items> 
                </telerik:RadComboBox> 
            </td> 
            <td class="toppadding5"
                <asp:TextBox TextMode="MultiLine" runat="server" ID="ShipTo" Text='<%# Bind("ShipTo") %>' 
                    Width="320px" Height="60px"></asp:TextBox> 
            </td> 
        </tr> 
        <tr> 
            <th class="lightgray label" colspan="2"
                Line Items 
            </th> 
        </tr> 
        <tr> 
            <td colspan="2"
                <asp:UpdatePanel runat="server"
                    <ContentTemplate> 
                        <table width="550px" cellspacing="0"
                            <tr> 
                                <th> 
                                    Description 
                                </th> 
                                <th> 
                                    Qty 
                                </th> 
                                <th> 
                                    Rate 
                                </th> 
                                <th> 
                                    Total 
                                </th> 
                            </tr> 
                            <asp:Repeater ID="LineItemRepeater" runat="server"
                                <ItemTemplate> 
                                    <tr> 
                                        <td> 
                                            <telerik:RadTextBox ID="Description" runat="server" Width="320px" Skin="MillenniumAdmin" 
                                                EnableEmbeddedSkins="false" Text='<%# Bind("Description") %>'
                                            </telerik:RadTextBox> 
                                        </td> 
                                        <td> 
                                            <telerik:RadNumericTextBox ID="Qty" runat="server" Type="Number" Width="80px" Skin="MillenniumAdmin" 
                                                EnableEmbeddedSkins="false" Text='<%# Bind("Qty") %>'
                                                <numberformat decimaldigits="0" /> 
                                            </telerik:RadNumericTextBox> 
                                        </td> 
                                        <td> 
                                            <telerik:RadNumericTextBox ID="Rate" runat="server" Type="Currency" Width="80px" 
                                                Skin="MillenniumAdmin" EnableEmbeddedSkins="false" Text='<%# Bind("Rate") %>'
                                                <numberformat decimaldigits="2" /> 
                                            </telerik:RadNumericTextBox> 
                                        </td> 
                                        <td> 
                                            <asp:Label ID="Total" runat="server" Width="80px"></asp:Label> 
                                        </td> 
                                    </tr> 
                                </ItemTemplate> 
                            </asp:Repeater> 
                        </table> 
                        <asp:LinkButton runat="server" ID="AddItemButton" OnClick="AddItemButton_Click"
                            <asp:Image runat="server" ImageUrl="~/images/telerik/insert.gif" CssClass="middle" /> Add an item</asp:LinkButton> 
                    </ContentTemplate> 
                </asp:UpdatePanel> 
            </td> 
        </tr> 
    </table> 
    <div id="RadGridButtons" runat="server" style="text-align: left"
        <asp:Button ID="btnUpdate" Text="Update" runat="server" CommandName="Update" Visible='<%# !((Container as GridItem).OwnerTableView.IsItemInserted) %>'
        </asp:Button> 
        <asp:Button ID="btnInsert" Text="Insert" runat="server" CommandName="PerformInsert" 
            Visible='<%# (Container as GridItem).OwnerTableView.IsItemInserted %>'></asp:Button> 
        &nbsp; 
        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" 
            CommandName="Cancel"></asp:Button> 
        <asp:LinkButton ID="SaveButton" runat="server" CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>' 
            OnClientClick="suppressConfirmation()"><img style="border:0px" alt="" src='../Images/Telerik/Update.gif'/></asp:LinkButton> 
        <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" CausesValidation="false" 
            OnClientClick="suppressConfirmation()"><img style="border:0px" alt="" src="../Images/Telerik/Cancel.gif" /></asp:LinkButton> 
    </div> 
</div> 
<asp:SqlDataSource ID="PublisherDataSource" runat="server" OnInit="SqlDataSource_Init" 
    SelectCommandType="StoredProcedure" SelectCommand="GetAllPublisherList"></asp:SqlDataSource> 
 

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 28 Jan 2009, 11:02 AM
Hello Kelly,

I believe the following links will help you implement desired functionality:
Automatic insert, update and delete with UserControl edit form for the grid
User control edit form

Greetings,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Kelly
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or