问题
When handling the OnUpdateCommand event on a RadGrid the DataItem is null.
I thought that this would also represent the data item being represented by the row.
The Radgrid is populated from an IList and in the handler the code looks like this...
protected void rgAllocatedClients_UpdateCommand(object sender, GridCommandEventArgs e)
{
if (e.Item is GridDataItem)
{
var gridDataItem = e.Item as GridDataItem;
var client= gridDataItem .DataItem as Client;
....
....
This works find when handling the ItemDataBound event but not when handling the UpdateCommand event. I really need this as in my Client class is the Id of the row I want to handle the update for.
Thanks,
回答1:
Try this by using GridEditableItem
protected void grdContacts_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
string idEditing = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"].ToString();
GridEditableItem editedItem = e.Item as GridEditableItem;
Hashtable newValues = new Hashtable();
// ur code
}
回答2:
Assuming your Grid is in Edit mode befor ethe Update Command, you should cast e.Item to GridEditableItem instead of GridDataItem
来源:https://stackoverflow.com/questions/2803565/telerik-radgrid-griddataitem-dataitem-is-empty-when-updating-onupdatecommand-ha