This is a migrated thread and some comments may be shown as answers.

[Solved] Check if column exists

2 Answers 310 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 16 Apr 2009, 01:25 PM
Hi,
I need to check if a column exists or not.
I have a global method that hides the edit/delete buttons on a row but now I have a grid without the edit button.
I tried this but getting error on the if statements: Cannot find a cell bound to column name 'EditCommandColumn'

public static void HideRadGridEditButtonsForReaders(GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                ImageButton editButton = null
                ImageButton deleteButton = null
                if(item["EditCommandColumn"] != null) 
                    editButton = (ImageButton)item["EditCommandColumn"].Controls[0]; 
                if (item["DeleteColumn"] != null) 
                    deleteButton = (ImageButton)item["DeleteColumn"].Controls[0]; 
                if (HttpContext.Current.User.IsInRole(Utilities.RoleTypes.AdministratorReaders.ToString())) 
                { 
                    if(editButton != null) editButton.Visible = false
                    if (deleteButton != null) deleteButton.Visible = false
                } 
            } 
        } 


2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 16 Apr 2009, 01:38 PM
Hello Mattias,

You can use the GetColumnSafe method to check whether the column exists or not:
if(RadGrid1.MasterTableView.GetColumnSafe("MyColumn") == null
    //... 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mattias
Top achievements
Rank 1
answered on 16 Apr 2009, 03:16 PM
Great! Thanks Daniel! :)
Tags
Grid
Asked by
Mattias
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or