This is a migrated thread and some comments may be shown as answers.

RadGrid Advanced Data Binding

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 24 Jul 2014, 10:26 AM
Dear Telerik,

I'm using advanced databinding on pageload in c#, and enabled batch edit mode as follow:

RadGrid_Strategy.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
                    RadGrid_Strategy.MasterTableView.EditMode = GridEditMode.Batch;
                    RadGrid_Strategy.MasterTableView.BatchEditingSettings.EditType = GridBatchEditingType.Cell;
                    RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
                    RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowSaveChangesButton = true;
                    RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowCancelChangesButton = true;
But I have 4 columns in table and would like to set readonly = "false" to some of them, as created programmatically, what property/event should I set to get access to these generated-on-the-fly column? Many thanks.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 24 Jul 2014, 12:42 PM
Hi Tim,

If you are creating columns from code behind, you can set the property there as follows:

C#:
//While creating columns
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
boundColumn.DataField = "Name";
boundColumn.ReadOnly = false;
RadGrid1.MasterTableView.Columns.Add(boundColumn);

To change the settings for declarative columns at runtime, write a handler for the PreRender event of the grid, traverse the Columnscollection to locate the column of interest, and alter its properties. You must then rebind the grid by calling its Rebind() method to reflect the changes.

C#:
protected void RadGrid1_PreRender(object sender, System.EventArgs e)
{
    foreach (GridColumn column in RadGrid1.Columns)
    {
        if (column.UniqueName == "Name")
        {
            (column as GridBoundColumn).ReadOnly = false;
             break;
        }
    }
    RadGrid1.Rebind();
}

Thanks,
Shinu
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or