Telerik RadGrid: Get updated values from controls in Edit mode

Hello,

This is the most common issue when new comers can not find the values they have updated from the Telerik RadGrid when editing a Grid Row data. You might want to use the UpdateCommand event to capture the Update event bubble from the Telerik RadGrid.

Now, when you create a new event method from Visual Studio, you will get GridCommandEventArgs as the second parameter which will be used to Render all the columns.

Follow below code to get the idea how a value from the TextBox and a CheckBox will be retrieved from the Grid in the Edit mode when the update command is given.

You will need to go through each Column to check if the column is editable or not. For TextBoxes you will find GridTextColumnEditor and CheckBoxes you will find GridCheckBoxColumnEditor to fetch the updated data. Now once you have got the data, you can go ahead and update the DataSet and Rebind the grid to reflect the change of Data.

/// <summary>
/// Handles the UpdateCommand event of the AttributesRadGrid control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="GridCommandEventArgs"/> instance containing the event data.</param>
protected void AttributesRadGrid_UpdateCommand(object sender, GridCommandEventArgs e)
{
    string labelText = string.Empty;
    bool isDisabled = false;

    GridEditableItem editedItem = e.Item as GridEditableItem;
    GridEditManager editManager = editedItem.EditManager;
    foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
    {
        if (column is IGridEditableColumn)
        {
            IGridEditableColumn editableCol = column as IGridEditableColumn;
            if (editableCol.IsEditable)
            {
                IGridColumnEditor editor = editManager.GetColumnEditor(editableCol);
                if (editor is GridTextColumnEditor)
                {
                    labelText = (editor as GridTextColumnEditor).Text;
                }

                if (editor is GridCheckBoxColumnEditor)
                {
                    isDisabled = (editor as GridCheckBoxColumnEditor).Value;
                }
            }
        }
    }

    // Load your DataSet to update the data
    // update the data from the DataSet

    this.something[index].Label = labelText;
    this.something[index].IsDisabled = isDisabled;

    // Rebind the RadGrid to show the updated data that is just updated to DataSet
    this.AttributesRadGrid.Rebind();
}

GridEditableItem: Represents the base class for any items that display and edit data in a Telerik.Web.UI.GridTableView of RadGrid. Inheritors has the capabilities to: Locate a table cell based on the column unique names Extract values from the cells of column editors Has a dictionary of saved-old-values that are necessary for optimistic concurency editing oprations Edit/browse mode EditManager instance, which is capable of locating the column editors.

Hope this helps! Happy Programming!!

Advertisements

One thought on “Telerik RadGrid: Get updated values from controls in Edit mode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s