[英]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.