Thanks,
9 Answers, 1 is accepted
You can use the new Batch editing functionality of RadGrid to achieve the requested functionality:
http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html
You can find a live example here:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/batchediting/defaultcs.aspx
Hope this helps.
Regards,
Eyup
Telerik
Please try the following approach:
protected
void
RadGrid1_BatchEditCommand(
object
sender, GridBatchEditingEventArgs e)
{
foreach
(GridBatchEditingCommand command
in
e.Commands)
{
Hashtable oldValues = command.OldValues;
Hashtable newValues = command.NewValues;
foreach
(
string
key
in
oldValues.Keys)
{
string
value = oldValues[key].ToString();
}
}
}
Or:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
GridBatchEditingEventArgument argument = e.CommandArgument
as
GridBatchEditingEventArgument;
if
(argument !=
null
)
{
Hashtable oldValues = argument.OldValues;
Hashtable newValues = argument.NewValues;
foreach
(
string
key
in
oldValues.Keys)
{
string
value = oldValues[key].ToString();
}
}
}
That should do the trick.
Regards,
Eyup
Telerik
Hi!
I am using batchEditUpdate and I have tried methods you provided above, but the OldValues for both methods only contains one element, the DataKeyNames. Why are there no columns of the grid in the OldValues? I need compare some fields of OldValues and NewValues. Any suggestions?
Thanks in advance!
Sharon
Not Sure if this will help any but I use the BatchEditCommand sub of the Grid
If IsPostBack Then
For Each item As GridBatchEditingCommand In e.Commands
Dim editedRow = item
Dim EditCol = dgCompGrid.Columns
Dim iRow As Int32
var1= (item.Item.GetDataKeyValue("field1").ToString())
var2 = (item.Item.GetDataKeyValue("field2").ToString())
iRow = item.Item.ItemIndex
For Each col As GridColumn In dgCompGrid.MasterTableView.Columns
If editedRow.NewValues(col.HeaderText) <> editedRow.OldValues(col.HeaderText) Then
iXSrcValue = col.HeaderText
ws.Update(var1, var2, editedRow.OldValues(col.HeaderText), Convert.ToDecimal(editedRow.NewValues(col.HeaderText)))
End If
Next
Next
End IF
Hi! Stefan,
Thank you for replying, but my problem is there are no elements (columns in the grid) in the Telerik specific variable - OldValues.
Thanks!
Sharon
Could you verify that you are not using DataBind() to bind the grid? Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations. Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding
Regards,
Eyup
Telerik
Hi! Eyup,
I use NeedDataSource, so, I think i am using Advanced databinding.
Thanks,
Sharon
Yes, Advanced databinding = Programmatic databinding = NeedDataSource event handler.
Regards,
Eyup
Telerik