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

Check if column unique name exists in dynamic radgrid

4 Answers 1544 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 27 Apr 2010, 02:19 AM
Hi,

I use a dynamically created RadGrid which means the column unique names are not always the same. I perform some data modification on ItemDataBound based on a columns unique name which works as expected if the column exists.
    protected void grvReport_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = ((GridDataItem)e.Item); 
            item["coltrainerList"].Text = item["coltrainerList"].Text.Replace(",", "<br/>"); 
        } 
        // Other unrelated stuff 
    } 

Of course, if the column does not exist I get an error alert "Cannot find a cell bound to column name 'coltrainerList'". I expected this also - but I am unsure of how to determine if it exists or not. I tried the following:
if (item["coltrainerList"] != null) item["coltrainerList"].Text = item["coltrainerList"].Text.Replace(",", "<br/>"); 




Unfortunately, I still get the error alert. I have looked through the GridDataItem functions and not found one that can check if a unique column name exists in order to avoid this error.

Have I missed something?

Cheers.

4 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 27 Apr 2010, 03:10 AM
I found a solution. I just need to use the FindByUniqueNameSafe function of the Item's OwnerTableView.Columns collection:
if (e.Item is GridDataItem)  
{  
     if (e.Item.OwnerTableView.Columns.FindByUniqueNameSafe("coltrainerList") != null)  
     {  
          GridDataItem item = ((GridDataItem)e.Item);  
          item["coltrainerList"].Text = item["coltrainerList"].Text.Replace(",", "<br/>");  
     }  
}  
0
msigman
Top achievements
Rank 2
answered on 02 Nov 2010, 12:06 AM
Thanks for posting the answer.  Helped me out!
0
Jason
Top achievements
Rank 1
answered on 09 Nov 2010, 12:04 AM
No problems. It is always annoying when someone says "Never mind I found the answer" and doesn't bother posting it :)

Would you mind marking the post as answer just for completeness?

Cheers,
Lourein
0
Bertha
Top achievements
Rank 1
answered on 06 Dec 2012, 04:50 PM
Thanks. It still help me!!
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
msigman
Top achievements
Rank 2
Bertha
Top achievements
Rank 1
Share this question
or