根据值更改单元格的背景颜色 [英] Change background color of cell based on value
本文介绍了根据值更改单元格的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有gridview,其中有empname,月份为列。每个单元格都有(A,P)值
i,e A表示缺席,P表示存在。我想设置背景颜色作为红色,其中单元格值是A
到现在为止我已经完成了这个但是我的问题仍然存在,你可以帮助我
I have gridview which have empname,date of month as columns.Every cell has (A,P) value
i,e A for absent and P for present.I want to set the background color as red where cell value is A
till now i have done this but my prob still remain can you help me
protected void PivotGridRowBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string val="";
foreach (TableCell cell in e.Row.Cells)
val = cell.Text;
if(val=="A")
{
}
}
}
[edit]已添加代码块[/ edit]
[edit]Code block added[/edit]
推荐答案
试试这个。 :)
try this. :)
foreach (TableCell cell in e.Row.Cells)
{
string val = cell.Text;
if (val == "A")
{
cell.BackColor = System.Drawing.Color.Red;
}
else
{
.......
}
}
参考.. :)
根据条件更改datagridview单元格颜色 [ ^ ]
使用C#基于ASP.Net中的条件动态更改GridView行背景颜色[ ^ ]
reference.. :)
Changing datagridview cell color based on condition[^]
Dynamically change GridView Row Background Color based on condition in ASP.Net using C# [^]
这篇关于根据值更改单元格的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文