[英]C# ASP.NET I can't set color on my Gridview when cell is empty
如果string
为empty
,我需要更改颜色,将其设置为红色
foreach (TableCell cell in e.Row.Cells)
{
if (cell.Equals(" ")||cell.Equals(string.Empty)||string.IsNullOrWhiteSpace(cell.ToString()))//if (cell.ToString() == " ")
{
cell.BackColor = Color.Red;
}
else
{
cell.BackColor = Color.White;
}
}
[ ]
foreach (TableCell cell in e.Row.Cells)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string text = cell.Text.Trim();
cell.BackColor = (String.IsNullOrEmpty(text) || text == " ") ? Color.Red : Color.White;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.