Hello, I use RadGrid in edit mode and I want to get cell value after changing it.
When I use UpdateCommand event, I get old value before changing.
protected
void gridEdit_UpdateCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
//TextBox txtbox = (TextBox)editItem["Value"].Controls[0]; //access the value
string value = (editItem["Value"].Controls[0] as TextBox).Text;
}
<telerik:RadGrid ID="gridEdit" runat="server" GridLines="None"
onupdatecommand="gridEdit_UpdateCommand"
<MasterTableView
EditMode="InPlace">
<Columns>
<telerik:GridEditCommandColumn />
</Columns>
</MasterTableView>
</telerik:RadGrid>
6 Answers, 1 is accepted
Please refer to this help topic for more information how to achieve the desired by you functionality.
Greetings,
Pavlina
the Telerik team
I click the edit link on the row, after that changing the value of editable column and then click update link but I continue to have the old value.
Can you please check whether you have tried the following code as descrides in the above help topic.
ASPX:
<
telerik:GridBoundColumn
DataField
=
"FirstName"
UniqueName
=
"FirstName"
>
</
telerik:GridBoundColumn
>
C#:
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item
as
GridEditableItem;
Hashtable newValues =
new
Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
string
v= newValues[
"FirstName"
].ToString();
//getting new value
}
Also verify that the ViewState of the RadGrid is enabled. Because if you set EnableViewState="false" , you will not get the new value.
Thanks,
Princy.
Attached to this message is a sample project which handles the desired functionality. Give it a try and let me know if it helps to resolve the problem.
Greetings,
Pavlina
the Telerik team
For example, the following code doesn't give me the new values i entered into the cells ... I get the old values (from db).
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem item = e.Item
as
GridEditableItem;
Hashtable newValues =
new
Hashtable();
//The GridTableView will fill the values from all editable columns in the hash
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, item);
var customerID = item.GetDataKeyValue(
"CustomerID"
).ToString();
Customer customer = DB.Customers.Where(p => p.CustomerID == customerID).FirstOrDefault();
customer.CompanyName = newValues[
"CompanyName"
].ToString();
DB.SaveChanges();
SetMessage(
"Customer updated!"
);
}
Thanks in advance.
Jorge