Batch Editing doesnt work with ajax

2 posts, 0 answers
  1. Rene
    Rene avatar
    11 posts
    Member since:
    Jan 2014

    Posted 08 Jul 2015 Link to this post

    Hey guys,

    im trying to follow the example from but i am unable to follow. I removed the datasource part becuase im not having the demo database installed and tried to use some static data instead but it seems like somehow neither my events nor the ajax stuff is fired. Anyone 



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using Telerik.Web.UI;
    namespace WebApplication2
        public partial class _Default : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
                DataTable dt = new DataTable();
                DataColumn dc1 = new DataColumn();
                dc1.ColumnName = "ProductID";
                dc1.Caption = "ProductID";
                dc1.DataType = typeof(int);
                DataColumn dc2 = new DataColumn();
                dc2.ColumnName = "ProductName";
                dc2.Caption = "ProductName";
                dc2.DataType = typeof(string);
                DataColumn dc3 = new DataColumn();
                dc3.ColumnName = "CategoryID";
                dc3.Caption = "CategoryID";
                dc3.DataType = typeof(int);
                DataColumn dc4 = new DataColumn();
                dc4.ColumnName = "CategoryName";
                dc4.Caption = "CategoryName";
                dc4.DataType = typeof(string);
                DataColumn dc5 = new DataColumn();
                dc5.ColumnName = "UnitPrice";
                dc5.Caption = "UnitPrice";
                dc5.DataType = typeof(decimal);
                DataColumn dc6 = new DataColumn();
                dc6.ColumnName = "Discontinued";
                dc6.Caption = "Discontinued";
                dc6.DataType = typeof(bool);
                DataColumn dc7 = new DataColumn();
                dc7.ColumnName = "UnitsInStock";
                dc7.Caption = "UnitsInStock";
                dc7.DataType = typeof(int);
                dt.Rows.Add(1, "name", 1, "cname", 20, false, 20);
                RadGrid1.DataSource = dt;
            protected void RadGrid1_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)
                SavedChangesList.Visible = true;
            protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
                GridEditableItem item = (GridEditableItem)e.Item;
                String id = item.GetDataKeyValue("ProductID").ToString();
                if (e.Exception != null)
                    e.KeepInEditMode = true;
                    e.ExceptionHandled = true;
                    NotifyUser("Product with ID " + id + " cannot be updated. Reason: " + e.Exception.Message);
                    NotifyUser("Product with ID " + id + " is updated!");
            protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
                if (e.Exception != null)
                    e.ExceptionHandled = true;
                    NotifyUser("Product cannot be inserted. Reason: " + e.Exception.Message);
                    NotifyUser("New product is inserted!");
            protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)
                GridDataItem dataItem = (GridDataItem)e.Item;
                String id = dataItem.GetDataKeyValue("ProductID").ToString();
                if (e.Exception != null)
                    e.ExceptionHandled = true;
                    NotifyUser("Product with ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);
                    NotifyUser("Product with ID " + id + " is deleted!");
            protected void RadGrid1_PreRender(object sender, EventArgs e)
                //RadNumericTextBox unitsNumericTextBox = (RadGrid1.MasterTableView.GetBatchColumnEditor("UnitsInStock") as GridNumericColumnEditor).NumericTextBox;
                //unitsNumericTextBox.Width = Unit.Pixel(60);
            private void NotifyUser(string message)
                RadListBoxItem commandListItem = new RadListBoxItem();
                commandListItem.Text = message;


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
    <%@ Register Assembly="Telerik.Web.UI, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
        Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
    <head id="Head1" runat="server">
        <title>Telerik ASP.NET Example</title>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="SavedChangesList" />
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1">
        <div id="demo" class="demo-container no-bg">
            <telerik:RadListBox runat="server" ID="SavedChangesList" Width="600px" Height="200px"
            <telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True"
                AllowAutomaticInserts="True" PageSize="10" OnItemDeleted="RadGrid1_ItemDeleted"
                OnItemInserted="RadGrid1_ItemInserted" OnItemUpdated="RadGrid1_ItemUpdated" OnPreRender="RadGrid1_PreRender"
                AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" OnBatchEditCommand="RadGrid1_BatchEditCommand">
                <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="ProductID" HorizontalAlign="NotSet"
                    EditMode="Batch" AutoGenerateColumns="False">
                    <BatchEditingSettings EditType="Cell" />
                        <telerik:GridSortExpression FieldName="ProductID" SortOrder="Descending" />
                        <telerik:GridBoundColumn DataField="ProductName" HeaderStyle-Width="210px" HeaderText="ProductName"
                            SortExpression="ProductName" UniqueName="ProductName">
                            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                <RequiredFieldValidator ForeColor="Red" Text="*This field is required" Display="Dynamic">
                        <telerik:GridNumericColumn DataField="UnitsInStock" HeaderStyle-Width="80px" HeaderText="Units In Stock"
                            SortExpression="UnitsInStock" UniqueName="UnitsInStock">
                        <telerik:GridCheckBoxColumn DataField="Discontinued" HeaderStyle-Width="80px" HeaderText="Discontinued"
                            SortExpression="Discontinued" UniqueName="Discontinued">
                        <telerik:GridTemplateColumn HeaderText="UnitPrice" HeaderStyle-Width="80px" SortExpression="UnitPrice"
                            UniqueName="TemplateColumn" DataField="UnitPrice">
                                <asp:Label runat="server" ID="lblUnitPrice" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
                                    <telerik:RadNumericTextBox Width="55px" runat="server" ID="tbUnitPrice">
                                    <span style="color: Red">
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbUnitPrice"
                                            ErrorMessage="*Required" runat="server" Display="Dynamic">
                        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px" ButtonType="ImageButton"
                            CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                <ClientSettings AllowKeyboardNavigation="true">

  2. Viktor Tachev
    Viktor Tachev avatar
    2407 posts

    Posted 13 Jul 2015 Link to this post

    Hi Rene,

    In the provided code the RadGrid is not data bound properly. You should bind the grid to a declarative DataSource control or via the NeedDataSource event.

    Also, in the sample code the automatic operations are enabled. Have in mind that in order to use automatic updates, inserts, deletes you should bind the grid to a declarative DataSource that supports automatic operations.

    For your convenience I have prepared a sample project that illustrates the approach. In the sample there is a RadGrid that is data-bound via the NeedDataSource event. It also uses manual CRUD operations.

    Viktor Tachev
    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 Feedback Portal and vote to affect the priority of the items
Back to Top