Hello,
I tried to implement batch updates. In my first try I used following article:
http://www.telerik.com/help/aspnet-ajax/grid-performing-batch-updates.html
I only used different table from Northwind database and used checkboxes for update.
Here you can see my code:
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?
I tried to implement batch updates. In my first try I used following article:
http://www.telerik.com/help/aspnet-ajax/grid-performing-batch-updates.html
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:radgrid
ID
=
"RadGrid1"
runat
=
"server"
AllowMultiRowEdit
=
"True"
DataSourceID
=
"SqlDataSource1"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
MasterTableView
DataKeyNames
=
"ProductID"
AutoGenerateColumns
=
"false"
EditMode
=
"InPlace"
CommandItemDisplay
=
"TopAndBottom"
>
<
Columns
>
<
telerik:gridboundcolumn
ReadOnly
=
"true"
DataField
=
"ProductID"
UniqueName
=
"ProductID"
HeaderText
=
"ProductID"
>
</
telerik:gridboundcolumn
>
<
telerik:gridboundcolumn
ReadOnly
=
"true"
DataField
=
"ProductName"
UniqueName
=
"ProductName"
HeaderText
=
"ProductName"
>
</
telerik:gridboundcolumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"Discontinued"
DefaultInsertValue
=
""
HeaderText
=
"Discontinued"
UniqueName
=
"Discontinued"
DataType
=
"System.int16"
>
</
telerik:GridCheckBoxColumn
>
<
telerik:grideditcommandcolumn
UniqueName
=
"EditCommandColumn"
/>
</
Columns
>
<
CommandItemTemplate
>
<
asp:Button
runat
=
"server"
ID
=
"UpdateAll"
Text
=
"Update All"
CommandName
=
"UpdateAll"
/></
CommandItemTemplate
>
</
MasterTableView
>
</
telerik:radgrid
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [Discontinued] FROM [Products]"
runat="server"></
asp:SqlDataSource
>
</
div
>
</
form
>
</
body
>
</
html
>
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());
SqlDataSource1.Update();
editedItem.Edit =
false
;
}
}
RadGrid1.Rebind();
}
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?