Search code examples
c#asp.nettelerikradgridtelerik-grid

Check if a Column Exists in a RadGrid


This is not finding the column. Anyone have any suggestions?

if (((RadGrid)sender).Columns.Contains("ClaimNumber"))
    do this...
else
    do this...

I checked the Columns Collection of the grid and I can see the column there.


Solution

  • You need to use the FindByUniqueNameSafe method:

    GridColumn col = RadRadGrid1.MasterTableView.Columns.FindByUniqueNameSafe("ColumnName");
    if (col != null)
    {
        //column exists
    }
    

    You could also use LINQ:

    if (RadGrid1.MasterTableView.Columns.Cast<GridColumn>().Count(x => x.UniqueName == "Column1") > 0)