Hi,
I am building my columns as below, but the caption remains as "MYCOL" as opposed to "My Column", this seems incorrect?
DataColumn dc = new DataColumn("MYCOL", System.String);
dc.Caption = "My Column";
dt.Columns.Add(dc);
3 Answers, 1 is accepted
0
Konstantin Dikov
Telerik team
answered on 10 Dec 2014, 01:19 PM
Hi Al,
With auto-generated columns, RadGrid will use the column's name for the UniqueName and the HeaderText of the generated columns. If you need to use the caption of the columns instead you can handle the server-side OnColumnCreated event, get reference to the DataTable set as a DataSource of the grid, traverse through the columns collection and manually set their caption as a HeaderText of the grid's columns:
IGridDataColumn column = e.Column as IGridDataColumn;
string columnName = column.GetActiveDataField();
RadGrid grid = sender as RadGrid;
if (grid.DataSourceObject != null)
{
DataTable table = grid.DataSource as DataTable;
foreach (DataColumn dColumn in table.Columns)
{
if (dColumn.ColumnName == columnName)
{
e.Column.HeaderText = dColumn.Caption;
}
}
}
}
}
Hope this helps.
Regards,
Konstantin Dikov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.