how to detect grid view empty cell ? I need it for highlighting. So I made a css
.RedColored
{
background: FF0000;
}
and trying to appear it to empty GV cells this way :
protected virtual GridView1_RowDataBound (_sender : object, e : System.Web.UI.WebControls.GridViewRowEventArgs) : void
{
e.Row.Cells[0].CssClass = "wide";
foreach(i : int in [0..e.Row.Cells.Count-1])
{
when(e.Row.Cells[i].Text==null)
{
e.Row.Cells[i].CssClass="RedColored";
}
}
}
but my it doesn’t appears to empty cells , even I’ve tried
Text==”” , Cell[i]==null, Cell[i].ToString()==”” and nothing helped.
recoded to :
def IsCellNull(cell : TableCell) : bool
{
| null => true
| c => string.IsNullOrEmpty(c.ToString()) || c.GetType().Name == "DBNull"
}
foreach(i : int in [0..e.Row.Cells.Count-1])
{
when(IsCellNull(e.Row.Cells[i]))
{
e.Row.Cells[i].Text="BLABLA";
e.Row.Cells[i].CssClass="RedColored";
}
}
But !!! It even doesn’t helped , it works without WHEN, but when (if) can not find empty cells 😛
Finally : solved with this code :` e.Row.Cells[0].CssClass = “wide”;
def IsCellNull(cell : TableCell) : bool
{
| null => true
| c => string.IsNullOrEmpty(c.ToString())
|| c.GetType().Name == "DBNull"
|| c.Text==" "
}
foreach(i : int in [0..e.Row.Cells.Count-1])
{
when(IsCellNull(e.Row.Cells[i]))
{
e.Row.Cells[i].BackColor=System.Drawing.Color.Red;
}
}`
In some browsers, the cell will not display a color if it is empty. Adding a space in it solves this issue, but then it will no longer be empty…
To test a cell, you should use string.IsNullOrEmpty():