protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
//Prepare new row to add it in the DataSource
===> DataRow[] changedRows = this.SqlDataSourceRate.Select(
"SnapShotID = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["SnapShotID"],
"Type = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Type"],
"Engine = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Engine"],
"Usage = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Usage"]);
//if (changedRows.Length != 1)
//{
// RadGrid1.Controls.Add(new LiteralControl("Unable to locate the Employee for updating."));
// e.Canceled = true;
// return;
//}
//Update new values
Hashtable newValues = new Hashtable();
newValues["UsageRate_Light_Rate"] = (userControl.FindControl("txtLightRate") as TextBox).Text;
newValues["Type"] = (userControl.FindControl("txtTypeNumber") as TextBox).Text;
newValues["Engine"] = (userControl.FindControl("txtTypeNumber") as TextBox).Text.Substring(0, 1);
newValues["MaxTerm_Heavy_Rate"] = (userControl.FindControl("txtMaxHeavyRate") as TextBox).Text;
newValues["MaxTerm_Medium_Rate"] = (userControl.FindControl("txtMaxMediumRate") as TextBox).Text;
newValues["MaxTerm_Light_Rate"] = (userControl.FindControl("txtMaxLightRate") as TextBox).Text;
newValues["UsageRate_Heavy_Rate"] = (userControl.FindControl("txtHeavyRate") as TextBox).Text;
newValues["UsageRate_Medium_Rate"] = (userControl.FindControl("txtMediumRate") as TextBox).Text;
newValues["UsageRate_Light_Rate"] = (userControl.FindControl("txtLightRate") as TextBox).Text;
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 += "Unable to update Employees. Reason: " + ex.Message;
e.Canceled = true;
}
}