Thanks for help with this.
I am passing a loaded datatable using a Session (Datatable) variable from another form to another form. I then copy the Session (Datatable) variable to a local datatable and then bind this datatable to a radgrid.
When a cell changes value and the "Save Changes" is clicked. All runs well but the entry.Value (newValue) is still showing old value.
changedRows[0][(string)entry.Key] = entry.Value;
Also, I tried to loop through the grid in the same routine but I still see the old value as well. I included the HTML code along with the update subroutine.
<telerik:RadGrid ID="grdIncome" runat="server" AllowAutomaticUpdates="True" AllowMultiRowSelection="True" Font-Names="Arial"
OnColumnCreated="grdIncome_OnColumnCreated" OnItemDataBound="grdIncome_ItemDataBound"
OnUpdateCommand="grdIncome_UpdateCommand"
OnItemUpdated="grdIncome_ItemUpdated" OnEditCommand="grdIncome_EditCommand" OnNeedDataSource="grdIncome_NeedDataSource1"
Skin="Silk" Width="100%" Font-Size="Small" ShowFooter="True" GridLines="None" AllowPaging="true" PageSize="20" >
<MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="AccountID"
AutoGenerateColumns="true" HorizontalAlign="NotSet" EditMode="InPlace" >
<BatchEditingSettings EditType="Cell" HighlightDeletedRows="true"/>
<Columns>
</Columns>
</MasterTableView>
</telerik:RadGrid>
protected void grdIncome_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
if (!UpdateRow(editedItem))
{
e.Canceled = true;
}
}
private bool UpdateRow(GridEditableItem editableItem)
{
//Locate the changed row in the DataSource
DataRow[] changedRows = SessionDataSource.Select(string.Format("AccountID = {0}", editableItem.GetDataKeyValue("AccountID")));
if (changedRows.Length != 1)
{
this.Label1.Text += "Unable to locate the Income Account for updating.";
return false;
}
for (int i = 0; i < grdIncome.MasterTableView.Items.Count; i++)
{
GridDataItem dataItem = (GridDataItem)grdIncome.MasterTableView.Items[i];
string strItemId = dataItem.GetDataKeyValue("AccountID").ToString();
Console.Write(dataItem["MM01"].Text);
}
//Update new values
Hashtable newValues = new Hashtable();
editableItem.OwnerTableView.ExtractValuesFromItem(newValues, editableItem);
changedRows[0].BeginEdit();
try
{
foreach (DictionaryEntry entry in newValues)
{
changedRows[0][(string)entry.Key] = entry.Value;
}
changedRows[0].EndEdit();
}
catch (Exception ex)
{
changedRows[0].CancelEdit();
Label1.Text += string.Format("Unable to update Orders. Reason: {0}", ex.Message);
return false;
}
return true;
}