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

Inserts/Updates/Deletes not working in batch editing

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nate
Top achievements
Rank 2
Nate asked on 28 Apr 2014, 03:52 PM
I'm using RadGrid in ASPX, .net 4.5. The data comes up and displays in my grid fine, but I cannot update, insert, or delete records. I have followed the sample version as closely as I can:

http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx

When I try to modify data in the grid, then hit Save, the grid reloads and the data is unchanged.

Originally I had the grid wrapped in ajax panel, but when these problems occurred, I removed it. That made not much difference; though when I was using ajax panel, often times clicking the Save icon did absolutely nothing. Or appeared to do nothing. So with that gone, the page/grid does normal postbacks EXCEPT that none of my event handlers are being called. Page_Load gets called, but nothing else (for example RadGrid1_BatchEditCommand, RadGrid1_ItemUpdated). It seems these should be getting called. 

ASPX:

<telerik:RadScriptManager runat="server" ID="RadScriptManager1" /><br>                <telerik:RadListBox runat="server" ID="SavedChangesList" Width="600px" Height="200px" Visible="false"></telerik:RadListBox><br>                <telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"<br>                    AllowAutomaticInserts="True" PageSize="10" Skin="Default" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"<br>                    OnItemUpdated="RadGrid1_ItemUpdated" OnPreRender="RadGrid1_PreRender" AllowAutomaticUpdates="True" AllowPaging="True"<br>                    AutoGenerateColumns="False" Width="1000px" OnBatchEditCommand="RadGrid1_BatchEditCommand" DataSourceID="sqlContractMatrix"><br>                    <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ID" DataSourceID="sqlContractMatrix" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False"><br>                        <BatchEditingSettings EditType="Cell" /><br>                        <SortExpressions><br>                            <telerik:GridSortExpression FieldName="SiteID,ProductID" SortOrder="Descending" /><br>                        </SortExpressions><br>                        <Columns><br>                            <telerik:GridTemplateColumn HeaderText="Site" HeaderStyle-Width="150px" UniqueName="SiteID" DataField="SiteID"><br>                                <ItemTemplate><br>                                    <%# Eval("SiteName") %><br>                                </ItemTemplate><br>                                <EditItemTemplate><br>                                    <telerik:RadDropDownList runat="server" ID="ddlSites" AppendDataBoundItems="true" DataValueField="SiteID" DataTextField="SiteName" DataSourceID="sqlSites"><br>                                            <br>                                    </telerik:RadDropDownList><br>                                </EditItemTemplate><br>                            </telerik:GridTemplateColumn><br> <br>                            <telerik:GridTemplateColumn HeaderText="Product" HeaderStyle-Width="150px" UniqueName="ProductID" DataField="ProductID"><br>                                <ItemTemplate><br>                                    <%# Eval("ProductName") %><br>                                </ItemTemplate><br>                                <EditItemTemplate><br>                                    <telerik:RadDropDownList runat="server" ID="ddlProducts" DropDownWidth="250" DropDownHeight="400" DefaultMessage="Product" AppendDataBoundItems="true" DataValueField="ProductID" DataTextField="ProductName" DataSourceID="sqlProducts"><br>                                            <br>                                    </telerik:RadDropDownList><br>                                </EditItemTemplate><br>                            </telerik:GridTemplateColumn><br>                                <br>                            <telerik:GridAttachmentColumn DataSourceID="sqlContractMatrix" MaxFileSize="1048576" HeaderStyle-Width="250px"<br>                                EditFormHeaderTextFormat="Upload File:" HeaderText="HTML Template" AttachmentDataField="BinaryData"<br>                                AttachmentKeyFields="ID" FileNameTextField="TemplateFileBinary" DataTextField="TemplateFileBinary"<br>                                UniqueName="TemplateFileBinary"><br>                            </telerik:GridAttachmentColumn><br> <br>                            <%--<br>                            <telerik:GridBoundColumn DataField="TemplateFile" HeaderStyle-Width="200px" HeaderText="Template"<br>                                SortExpression="TemplateFile" UniqueName="TemplateFile"><br>                            </telerik:GridBoundColumn><br>                            --%><br> <br>                            <telerik:GridBoundColumn DataField="PDFName" HeaderStyle-Width="200px" HeaderText="PDF Name"<br>                                SortExpression="PDFName" UniqueName="PDFName"><br>                            </telerik:GridBoundColumn><br>                            <telerik:GridButtonColumn ConfirmText="Delete this record?" ConfirmDialogType="RadWindow"<br>                                ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px" ButtonType="ImageButton"<br>                                CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"><br>                            </telerik:GridButtonColumn><br>                        </Columns><br>                    </MasterTableView><br>                </telerik:RadGrid><br>                <asp:SqlDataSource ID="sqlContractMatrix" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>"<br>                    DeleteCommand="DELETE FROM ContractMatrix WHERE ID = @ID" <br>                    InsertCommand="INSERT INTO ContractMatrix (SiteID, ProductID, TemplateFile, PDFName, LastModifiedDate, LastModifiedByID) VALUES (@SiteID, @ProductID, @TemplateFile, @PDFName, @LastModifiedDate, @LastModifiedByID)"<br>                    UpdateCommand="UPDATE ContractMatrix SET SiteID = @SiteID, ProductID = @ProductID, TemplateFile = @TemplateFile, PDFName = @PDFName, LastModifiedDate = GETDATE(), LastModifiedByID = @LastModifiedByID WHERE ID = @ID"><br>                    <DeleteParameters><br>                        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter><br>                    </DeleteParameters><br>                    <InsertParameters><br>                        <asp:Parameter Name="SiteID" Type="Int32"></asp:Parameter><br>                        <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter><br>                        <asp:Parameter Name="TemplateFile" Type="String"></asp:Parameter><br>                        <asp:Parameter Name="PDFName" Type="String"></asp:Parameter><br>                    </InsertParameters><br>                    <UpdateParameters><br>                        <asp:Parameter Name="SiteID" Type="Int32"></asp:Parameter><br>                        <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter><br>                        <asp:Parameter Name="TemplateFile" Type="String"></asp:Parameter><br>                        <asp:Parameter Name="PDFName" Type="String"></asp:Parameter><br>                        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter><br>                    </UpdateParameters><br>                </asp:SqlDataSource><br>                <br>                <!-- SQL data sources for various lookup tables --><br>                <asp:SqlDataSource ID="sqlSites" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT SiteID, SiteName FROM gym.Site ORDER BY SiteID"></asp:SqlDataSource><br>                <asp:SqlDataSource ID="sqlProducts" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>" ProviderName="System.Data.SqlClient"></asp:SqlDataSource>

C#: 
protected void RadGrid1_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)<br>        {<br>            SavedChangesList.Visible = true;<br>        }<br> <br>        protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)<br>        {<br>            GridEditableItem item = (GridEditableItem)e.Item;<br>            string id = item.GetDataKeyValue("ID").ToString();<br>            if (e.Exception != null)<br>            {<br>                e.KeepInEditMode = true;<br>                e.ExceptionHandled = true;<br>                NotifyUser("Record with ID " + id + " cannot be updated. Reason: " + e.Exception.Message);<br>            }<br>            else<br>            {<br>                NotifyUser("Record with ID " + id + " is updated!");<br>            }<br>        }<br> <br>        protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)<br>        {<br>            if (e.Exception != null)<br>            {<br>                e.ExceptionHandled = true;<br>                NotifyUser("Product cannot be inserted. Reason: " + e.Exception.Message);<br>            }<br>            else<br>            {<br>                NotifyUser("New product is inserted!");<br>            }<br>        }<br> <br>        protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)<br>        {<br>            GridDataItem dataItem = (GridDataItem)e.Item;<br>            string id = dataItem.GetDataKeyValue("ID").ToString();<br>            if (e.Exception != null)<br>            {<br>                e.ExceptionHandled = true;<br>                NotifyUser("Product with ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);<br>            }<br>            else<br>            {<br>                NotifyUser("Product with ID " + id + " is deleted!");<br>            }<br> <br>        }


Please help. Why are the data updates not occurring?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 29 Apr 2014, 11:24 AM
Hi Nate,

Can you please re-write your DataSource as below and check if the issue exist.

ASPX:
<asp:SqlDataSource ID="sqlContractMatrix" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>"
DeleteCommand="DELETE FROM [ContractMatrix] WHERE ID=@ID"
InsertCommand="INSERT INTO [ContractMatrix] ([SiteID], [ProductID], [TemplateFile], [PDFName], [LastModifiedDate], [LastModifiedByID]) VALUES (@SiteID, @ProductID, @TemplateFile, @PDFName, @LastModifiedDate, @LastModifiedByID)"
UpdateCommand="UPDATE [ContractMatrix] SET [SiteID]=@SiteID, [ProductID]=@ProductID, [TemplateFile]=@TemplateFile, [PDFName]=@PDFName,[LastModifiedDate]=GETDATE(), [LastModifiedByID]=@LastModifiedByID WHERE ID=@ID">
    <DeleteParameters>
        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="SiteID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="TemplateFile" Type="String"></asp:Parameter>
        <asp:Parameter Name="PDFName" Type="String"></asp:Parameter>
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="SiteID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="ProductID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="TemplateFile" Type="String"></asp:Parameter>
        <asp:Parameter Name="PDFName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>
 
<!-- SQL data sources for various lookup tables -->
<asp:SqlDataSource ID="sqlSites" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [SiteID], [SiteName] FROM gym.Site ORDER BY [SiteID]">
</asp:SqlDataSource>
 
<asp:SqlDataSource ID="sqlProducts" runat="server" ConnectionString="<%$ ConnectionStrings:FitTrack %>" ProviderName="System.Data.SqlClient">
</asp:SqlDataSource>

Thanks,
Princy
Tags
Grid
Asked by
Nate
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Share this question
or