如何检测网格视图的空单元格 [英] how to detect grid view empty cell

查看:60
本文介绍了如何检测网格视图的空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测网格视图中的空白单元格?,我需要用它来突出显示.所以我做了一个CSS

how to detect grid view empty cell ? I need it for highlighting. So I made a css

.RedColored 
{
    background: FF0000;
}

并尝试以这种方式将其显示为清空GV单元:

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

但是我似乎并没有清空单元格,即使我已经尝试过Text ==",Cell [i] == null,Cell [i] .ToString()==",没有任何帮助.

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

但是!!!它甚至没有帮助,它可以在没有WHEN的情况下工作,但是当(if)找不到空单元格时:P 最后:用此代码解决:`e.Row.Cells [0] .CssClass ="wide";

But !!! It even doesn't helped , it works without WHEN, but when (if) can not find empty cells :P 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...

要测试单元格,应使用string.IsNullOrEmpty():

To test a cell, you should use string.IsNullOrEmpty():

when(string.IsNullOrEmpty(e.Row.Cells[i].Text))
{
  e.Row.Cells[i].Text=" "; // Or sometimes a no break space -   will work better
  e.Row.Cells[i].CssClass="RedColored";
}

这篇关于如何检测网格视图的空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆