How to iterate Telerik Asp.net RadGrid Cells and modify the cell value

telerik-grid

I need to iterate through the RadGrid cells in the ItemDatabound event and modify the cell values. All of the examples on the Telerik support site achieve this by using the Unique Column name. In my situation, I need to achieve this by iterating the cell values, retrieving the values and then setting a new value without using the column Uniquename.

Any ideas?

Best Answer

Figured it out - In ItemDataBound:

    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        int columnCount = ((DataRowView)dataItem.DataItem).Row.Table.Columns.Count;
        string cellValue = string.Empty;
        string uniqueColumnname = string.Empty;

                for (int x = 0; x < columnCount; x++)
                {
                    uniqueColumnname = ((DataRowView)dataItem.DataItem).Row.Table.Columns[x].ToString();
                    cellValue = ((DataRowView)dataItem.DataItem)[uniqueColumnname].ToString();

                    if (string.IsNullOrEmpty(cellValue.ToString()))
                    {
                        TableCell cell = dataItem[uniqueColumnname];
                        cell.Text = "n/a";
                    }
                }
    }
Related Topic