Check if column unique name exists in dynamic radgrid

5 posts, 0 answers
  1. Jason
    Jason avatar
    26 posts
    Member since:
    Nov 2006

    Posted 26 Apr 2010 Link to this post

    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.
  2. Jason
    Jason avatar
    26 posts
    Member since:
    Nov 2006

    Posted 26 Apr 2010 Link to this post

    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/>");  
         }  
    }  
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 01 Nov 2010 Link to this post

    Thanks for posting the answer.  Helped me out!
  5. Jason
    Jason avatar
    26 posts
    Member since:
    Nov 2006

    Posted 08 Nov 2010 Link to this post

    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
  6. Bertha
    Bertha avatar
    56 posts
    Member since:
    Aug 2012

    Posted 06 Dec 2012 Link to this post

    Thanks. It still help me!!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017