Accessing the columns of a Detail Table that belongs to a RadGrid can be difficult.
I wanted to make some columns ReadOnly because they are Data Key Names or Foreign Key Names. There may be another way to achieve this behaviour but I could not find it.
Below is the solution I came up with.
/// <summary>
/// Makes the ID rows readonly. Have to use because the cols are Generated automatically
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
protected void Websites_RadGrid_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
//##DetailTableDataBind Info at:
//http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingdetailtabledatabind.html
//Get the required cols
var Col1 = e.DetailTableView.AutoGeneratedColumns.SingleOrDefault(ColName => ColName.IsBoundToFieldName("DomainID"));
var Col2 = e.DetailTableView.AutoGeneratedColumns.SingleOrDefault(ColName => ColName.IsBoundToFieldName("WebSiteID"));
//If the col exists them make it read only.
if (Col1 != null)
{
(Col1 as Telerik.Web.UI.GridBoundColumn).ReadOnly = true;
}
if (Col2 != null)
{
(Col2 as Telerik.Web.UI.GridBoundColumn).ReadOnly = true;
}
}