New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

RadGrid appends 1 to the unique names of auto generated columns

Description

The AutoGenerateColumns of the grid are enabled by default. To modify their settings or implement some custom logic in the code-behind, you can use the OnColumnCreated event handler:

Customizing auto-generated columns

Using the e.Column.UniqueName property within this handler causes the grid to generate and assign this name explicitly. The internal auto-column generation logic afterwards may append 1 at the end of the column name since it finds an already existing column with the same name.

This may lead to the following error:
Cannot find a cell bound to column name "MyColumnName".

Solution

To avoid this, instead of accessing the UniqueName of the auto-generated column, you can use its DataField property.

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    IGridDataColumn column = e.Column as IGridDataColumn;
    if(column != null) {
        string currColumnField = column.GetActiveDataField();
        //instead of using e.Column.UniqueName
        //as this usually be the same for autogenerated columns
    }
}
In this article
Not finding the help you need? Improve this article