Telerik RadGrid GridDataItem - how to determine if a column exists?

I use the base class to change the behavior of any Telerik RadGrid that appears on my ASP.Net pages. In the base class, I want to perform certain operations (install Css, tool tips, etc.) in many common columns, but not every common column exists in every grid.

In the ItemDataBound event, I get an instance in GridDataItem, and in turn I want to get a link to one or more contained GridDataItem cells:

var cell = gridDataItem["ColumnUniqueName"] 

The problem is that this throws a GridException if the named column does not exist:

Could not find cell associated with column name 'ColumnUniqueName'

Is there a way to check for a column by name before referencing it, or am I stuck with try catch?

+6
source share
2 answers

Sends me the right way:

 var tableView = gridDataItem.OwnerTableView; var gridColumn = tableView.Columns.FindByUniqueNameSafe(uniqueName); if (gridColumn != null) { var cell = gridDataItem[gridColumn]; ... 
+6
source

Try using the RenderColumns collection:

 protected void rgGrid_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { bool found = (from d in rgGrid.MasterTableView.RenderColumns select d).Any(d => d.UniqueName == "ColumnUniqueName"); } } 
+5
source

Source: https://habr.com/ru/post/957604/


All Articles