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

11,195

Solution 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
}

Solution 2

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

Share:
11,195
Charlie Kou
Author by

Charlie Kou

Updated on June 04, 2022

Comments

  • Charlie Kou
    Charlie Kou about 2 years

    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,