We're building a proof-of-concept using this Telerik example:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx
I've got the databound ok, however cannot get the update functionality to work at all.
Since the example is shown using a design-time datasource, we're having difficulty figuring out how to set up the update functionality for the grid since it is being bound at runtime.
I'm also using a demo version, so I am not well-acquainted with your controls, however have been developing ASP.Net web forms pages for over 10 years..
Code files are attached.
Thanks
2 Answers, 1 is accepted
0
JazzBox
Top achievements
Rank 1
answered on 02 May 2016, 08:41 PM
Code wasn't permissible to attach.
Here's our code:
ASPX:
<%@ Page Language="C#" MasterPageFile="~/PrissmWeb.master" AutoEventWireup="true" CodeFile="ActionGroupListTest.aspx.cs" Theme="SkinFile" Inherits="ActionGroupListTest" Title="Action Group List Test" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"MainContentPlaceHolder"
Runat
=
"Server"
>
<
telerik:RadStyleSheetManager
ID
=
"RadStyleSheetManager1"
runat
=
"server"
>
</
telerik:RadStyleSheetManager
>
<
script
src
=
"Scripts/jquery-2.2.0.min.js"
type
=
"text/javascript"
></
script
>
<
telerik:RadCodeBlock
ID
=
"radCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function: validate Rank entries
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
$(document).ready(function () {
//validate edit
$("#txtRank").blur(function () {
var isNum = $.isNumeric($("#txtRank").val());
if (!isNum) {
alert("Please enter a number");
$("#txtRank").val('');
$("#txtRank").focus();
}
});
//validate New Rank
$("#txtNewRank").blur(function () {
var isNum = $.isNumeric($("#txtNewRank").val());
if (!isNum) {
alert("Please enter a number");
$("#txtNewRank").val('');
$("#txtNewRank").focus();
}
});
});
function displayButtons(cellvalue, options, rowObject) {
var edit = "<
input
style
=
'...'
type
=
'button'
value
=
'Go To'
onclick=\"alert();\" />";
return edit;
}
</
script
>
</
telerik:RadCodeBlock
>
<
div
>
<
table
class
=
"FullWidthContent"
cellpadding
=
"0"
cellspacing
=
"1"
border
=
"0"
>
<
tr
>
<
td
style
=
"width: 662px; height: 16px"
>
<%--<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGridActionGroup"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridActionGroup"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"SavedChangesList"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"ConfigurationPanel1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGridActionGroup"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"RadAjaxLoadingPanel1"
></
telerik:RadAjaxLoadingPanel
>--%>
<
telerik:RadFormDecorator
RenderMode
=
"Lightweight"
ID
=
"RadFormDecorator1"
runat
=
"server"
DecorationZoneID
=
"demo"
DecoratedControls
=
"All"
EnableRoundedCorners
=
"false"
/>
<
telerik:RadGrid
ID
=
"RadGridActionGroup"
runat
=
"server"
RenderMode
=
"Lightweight"
AllowAutomaticDeletes
=
"false"
AllowAutomaticInserts
=
"false"
AllowAutomaticUpdates
=
"false"
onitemdatabound
=
"RadGridActionGroup_ItemDataBound"
onbatcheditcommand
=
"RadGridActionGroup_BatchEditCommand"
GroupPanelPosition
=
"Top"
IsExporting
=
"False"
onitemdeleted
=
"RadGridActionGroup_ItemDeleted"
oniteminserted
=
"RadGridActionGroup_ItemInserted"
onitemupdated
=
"RadGridActionGroup_ItemUpdated"
oncancelcommand
=
"RadGridActionGroup_CancelCommand"
>
<
MasterTableView
CommandItemDisplay
=
"TopAndBottom"
DataKeyNames
=
"ID"
EditMode
=
"Batch"
AutoGenerateColumns
=
"false"
>
<
BatchEditingSettings
EditType
=
"Cell"
/>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"ID"
DataField
=
"ID"
HeaderStyle-Width
=
"20px"
/>
<
telerik:GridTemplateColumn
HeaderText
=
"Rank"
UniqueName
=
"Rank"
DataField
=
"Rank"
HeaderStyle-Width
=
"20px"
>
<
ItemTemplate
>
<%# Eval("Rank")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
RenderMode
=
"Lightweight"
Width
=
"20px"
runat
=
"server"
ID
=
"txtRank"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Name"
UniqueName
=
"Name"
DataField
=
"Name"
HeaderStyle-Width
=
"100px"
>
<
ItemTemplate
>
<%# Eval("Name")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadTextBox
RenderMode
=
"Lightweight"
Width
=
"100px"
runat
=
"server"
ID
=
"txtName"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Description"
UniqueName
=
"Description"
DataField
=
"Description"
HeaderStyle-Width
=
"150px"
>
<
ItemTemplate
>
<%# Eval("Description")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadTextBox
RenderMode
=
"Lightweight"
TextMode
=
"MultiLine"
Width
=
"150px"
runat
=
"server"
ID
=
"txtDescription"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Code"
UniqueName
=
"Code"
DataField
=
"Code"
HeaderStyle-Width
=
"25px"
>
<
ItemTemplate
>
<%# Eval("Code")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadTextBox
RenderMode
=
"Lightweight"
Width
=
"25px"
runat
=
"server"
ID
=
"txtCode"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Version Number"
UniqueName
=
"VersionNumber"
DataField
=
"VersionNumber"
HeaderStyle-Width
=
"50px"
>
<
ItemTemplate
>
<%# Eval("VersionNumber")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadTextBox
RenderMode
=
"Lightweight"
Width
=
"50px"
runat
=
"server"
ID
=
"txtVersionNumber"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"ActionGroupType"
DataField
=
"ActionGroupTypeId"
HeaderStyle-Width
=
"100px"
>
<
ItemTemplate
>
<
telerik:RadDropDownList
RenderMode
=
"Lightweight"
runat
=
"server"
ID
=
"ddActionGroupType"
DataValueField
=
"Id"
DataTextField
=
"Name"
>
</
telerik:RadDropDownList
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadDropDownList
RenderMode
=
"Lightweight"
runat
=
"server"
ID
=
"ddActionGroupType2"
DataValueField
=
"Id"
DataTextField
=
"Name"
>
</
telerik:RadDropDownList
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
<
BatchEditingSettings
/>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
></
ClientSettings
>
</
telerik:RadGrid
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
asp:Content
>
C#
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
Ppd.Prissm.ModelTier;
using
Telerik.Web.UI;
public
partial
class
ActionGroupListTest : ConfigToolPageBase
{
private
string
scrollValue =
""
;
private
bool
check =
false
;
#region PageLoad
protected
void
Page_Load(
object
sender, EventArgs e)
{
try
{
Label labeltmp = (Label)Page.Master.FindControl(
"lblMessage"
);
Label labeltmp1 = (Label)Page.Master.FindControl(
"lblCommitChk"
);
Label labeltmp2 = (Label)Page.Master.FindControl(
"lblSourceSchema"
);
if
(ConfigurationController.GetVersion() ==
"2.1"
|| Convert.ToDouble(ConfigurationController.GetVersion()) >= 3.0)
check =
true
;
base
.PageTitle =
"Action Group List"
;
if
(!IsPostBack)
{
//SmartScroller1.ScrollToObject("grdActionGroup");
DataBindData();
BindDropDown();
}
//Load external JavaScript file. Before user deleting an action group
//ConfirmOnDelete function will be called.
Page.ClientScript.RegisterClientScriptInclude(
"mykey"
,
"common_javascript.js"
);
}
catch
(Exception ex)
{
ConfigurationController.ClearMessages();
ConfigurationController.AddMessage(
"Error loading the page. try again"
);
}
}
#endregion
#region bindevents
protected
void
DataBindData()
{
try
{
ActionGroupsModel actionGroups = ConfigurationController.GetAllActionGroups();
RadGridActionGroup.DataSource = actionGroups.ActionGroupsModel;
RadGridActionGroup.DataBind();
}
catch
(Exception ex)
{
ConfigurationController.AddMessage(ex.Message.ToString());
}
}
protected
void
BindDropDown()
{
//datasource for dropdown
ActionGroupTypesModel actionGroupTypes = ConfigurationController.GetAllActionGroupTypes();
//casting the datasource to an ICollection type
ICollection coll = actionGroupTypes.ActionGroupTypesModel;
}
#endregion
protected
void
grdActionGroup_RowUpdating(
object
sender, GridViewUpdateEventArgs e) { }
protected
void
grdActionGroup_RowDeleting(
object
sender, GridViewDeleteEventArgs e) { }
protected
void
RadGridActionGroup_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridItem)
{
GridItem item = (GridItem)e.Item;
RadDropDownList ddList = (RadDropDownList)item.FindControl(
"ddActionGroupType"
);
if
(ddList !=
null
)
{
//datasource for dropdown
ActionGroupTypesModel actionGroupTypes = ConfigurationController.GetAllActionGroupTypes();
//casting the datasource to an ICollection type
ICollection coll = actionGroupTypes.ActionGroupTypesModel;
ddList.DataSource = coll;
ddList.DataTextField =
"Name"
;
ddList.DataValueField =
"Id"
;
ddList.DataBind();
}
}
}
protected
void
RadGridActionGroup_BatchEditCommand(
object
sender, GridBatchEditingEventArgs e)
{
}
protected
void
RadGridActionGroup_ItemDeleted(
object
sender, GridDeletedEventArgs e)
{
}
protected
void
RadGridActionGroup_ItemInserted(
object
sender, GridInsertedEventArgs e)
{
}
protected
void
RadGridActionGroup_ItemUpdated(
object
sender, GridUpdatedEventArgs e)
{
}
protected
void
RadGridActionGroup_CancelCommand(
object
sender, GridCommandEventArgs e)
{
DataBindData();
}
protected
void
RadGridActionGroup_ItemCommand(
object
sender, GridCommandEventArgs e)
{
try
{
foreach
(GridEditableItem editedItem
in
RadGridActionGroup.EditItems)
{
Hashtable newValues =
new
Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
}
}
catch
(Exception ex)
{
ConfigurationController.AddMessage(ex.Message.ToString());
}
}
}
0
Hi Doug,
I have examined the code and noticed that you are using DataBind() to bind the RadGrid control. Note that this method is used for simple data binding. As the name implies this binding is suitable only for the most simple scenarios.
In order to have the Batch Editing work as expected you would need to use advanced data binding. You need to handle the NeedDataSource event and set the DataSource property for the grid there. Have in mind that DataBind() for the grid must not be called anywhere in the code.
For your convenience I am attaching a sample project that outlines how you can bind and edit a RadGrid in Batch Edit mode.
If you would like additional information on Batch Edit mode you would find the Batch editing section in the documentation interesting:
Regards,
Viktor Tachev
Telerik
I have examined the code and noticed that you are using DataBind() to bind the RadGrid control. Note that this method is used for simple data binding. As the name implies this binding is suitable only for the most simple scenarios.
In order to have the Batch Editing work as expected you would need to use advanced data binding. You need to handle the NeedDataSource event and set the DataSource property for the grid there. Have in mind that DataBind() for the grid must not be called anywhere in the code.
For your convenience I am attaching a sample project that outlines how you can bind and edit a RadGrid in Batch Edit mode.
If you would like additional information on Batch Edit mode you would find the Batch editing section in the documentation interesting:
Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.