Telerik Radgrid GridDataItem.DataItem is empty when updating (OnUpdateCommand handler)

asp.netradgridtelerik

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,

Best Answer

Assuming your Grid is in Edit mode befor ethe Update Command, you should cast e.Item to GridEditableItem instead of GridDataItem

Related Topic