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

Performing Batch Updates

1 Answer 47 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
berto asked on 24 Nov 2012, 08:35 PM

I tried to implement batch updates. In my first try I used following article:

I only used different table from Northwind database and used checkboxes for update.

Here you can see my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<head runat="server">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <telerik:radgrid ID="RadGrid1" runat="server" AllowMultiRowEdit="True" DataSourceID="SqlDataSource1"
  <MasterTableView DataKeyNames="ProductID" AutoGenerateColumns="false" EditMode="InPlace"
      <telerik:gridboundcolumn ReadOnly="true" DataField="ProductID" UniqueName="ProductID"
      <telerik:gridboundcolumn ReadOnly="true" DataField="ProductName" UniqueName="ProductName"
      <telerik:GridCheckBoxColumn DataField="Discontinued" DefaultInsertValue=""
                    HeaderText="Discontinued" UniqueName="Discontinued" DataType="System.int16">
      <telerik:grideditcommandcolumn UniqueName="EditCommandColumn" />
      <asp:Button runat="server" ID="UpdateAll" Text="Update All" CommandName="UpdateAll" /></CommandItemTemplate>
<asp:SqlDataSource ID="SqlDataSource1"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [ProductID], [ProductName], [Discontinued] FROM [Products]"

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        if (e.CommandName == "UpdateAll")
            foreach (GridEditableItem editedItem in RadGrid1.EditItems)
                Hashtable newValues = new Hashtable();
                //The GridTableView will fill the values from all editable columns in the hash
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                SqlDataSource1.UpdateCommand = String.Format("Update Products SET Discontinued='{0}' WHERE ProductID='{1}'"
                    , newValues["Discontinued"], editedItem.GetDataKeyValue("ProductID").ToString());
                editedItem.Edit = false;
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        if (e.Item is GridDataItem && e.Item.IsInEditMode)
            GridDataItem dataItem = e.Item as GridDataItem;
            //Hides the Update button for each edit form
            dataItem["EditCommandColumn"].Controls[0].Visible = false;

It seems that batch update does not work. When I click edit I can change checkbox value but when I click edit on second record change I did disappers. somhow it is not remembered. Can you fix this problem, please?

1 Answer, 1 is accepted

Sort by
Angel Petrov
Telerik team
answered on 28 Nov 2012, 01:08 PM
Hello Andrzej,

When the edit form is opened RadGrid is being recreated thus temporary data is being lost. However you can workaround this issue by storing the temporary changes and reapply them in ItemDataBound. On how to implement this please review the attached project which I created using your code.

All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question