How do I set Telerik RadGrid to Edit mode by defau

2020-06-17 07:16发布

问题:

I have a checkbox column in a RadGrid that I want the user to be able to check/uncheck it and set the attached property. When the grid renders however, the checkboxes are disabled, because the grid is not in "edit mode". All the examples I'm finding want me to go through a lengthy process of selecting the record, putting it into edit mode, changing the value, saving the value.... yada yada yada...

I just want the whole grid to be in edit mode (or the column, or whatever works) from the get-go, so the end user can make a one-click change to the data value.

I know there must be a way to do this, I just can't seem to find it.

Help?

回答1:

You can put it into edit mode by calling on the pre-render event for the grid.

Here is some sample C# code to do that.

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (IsPostBack) return;

    foreach (var item in RadGrid1.MasterTableView.Items)
    {
        var editableItem = item as GridEditableItem;
        if (editableItem == null) continue;

        editableItem.Edit = true;
        PreviewRadGrid.Rebind();
    }       
}

http://www.telerik.com/help/aspnet/grid/grddefaulteditmodeforgriditemsoninitialload.html