RadGrid - 根据第一列值格式化整行中的所有项目

时间:2015-07-26 22:10:22

标签: asp.net webforms telerik telerik-grid radgrid

我试图弄清楚如何根据第一列的值来格式化整行中的数字。

例如,在ItemDataBound事件中,我尝试执行以下操作:

if (item["Category"] == "Category 1")
{
     // this makes all items in the row red
     item.ForeColor = Color.Red;

     // now is it possible to format all numbers in the row as percent
}

通常你通过在每列上设置Format来处理这种事情,但在我的情况下,我的列是动态创建的,我需要将每行的格式基于第一列值。

某些行需要格式化为百分比,某些货币,一些小数。

以下是如果有帮助的话,如何创建网格的列:

var boundColumn = new GridBoundColumn();
gridDealAssumption.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "Category";
boundColumn.ItemStyle.Font.Bold = true;


foreach (string product in products)
{
    GridNumericColumn numericColumn = new GridNumericColumn();
    gridDealAssumption.MasterTableView.Columns.Add(numericColumn);
    numericColumn.DataField = product
    numericColumn.HeaderText = product;
}

正如您所看到的,我的Category Column是唯一的静态列,它是一个常规绑定列。其他列都是动态GridNumericColumns。

0 个答案:

没有答案