5 telerik radgrid cell-formatting
我必须根据单元格的值格式化(backcolor,forecolor,font style)radgrid的单元格.
例如,如果值为负,则将该单元格的前景颜色设置为红色.
任何人都可以告诉我这是如何实现的?
protected void grdName_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
{
TableCell cell = item["Column"];
cell.BackColor = Color.PeachPuff;
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 4
将 onItemDataBound="Data_OnitemDataBound" 行添加到 aspx 页面中的 radGrid 声明中。
然后将其添加到您的代码后面。Cells[] 中的数字是您要修改或验证的列的索引。
protected void Data_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToDecimal(item.Cells[3].Text) < 0)
{
item.Cells[3].ForeColor = System.Drawing.Color.Red;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30265 次 |
| 最近记录: |