简体   繁体   中英

C# ASP.NET I can't set color on my Gridview when cell is empty

I need to change color if string is empty it set to red color

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM