Asp Dot Net Notes for Web Masters RSS 2.0
# Tuesday, February 02, 2010
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;
    }
}

Tuesday, February 02, 2010 12:07:10 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
Controls
Archive
<February 2010>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
I do I.T. Ltd.
Sign In
Statistics
Total Posts: 23
This Year: 2
This Month: 0
This Week: 0
Comments: 1
All Content © 2010, I do I.T. Ltd.