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

这一生的挚爱 提交于 2019-12-11 00:15:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!