如何检测网格视图的空单元格

编程入门 行业动态 更新时间:2024-10-10 21:22:22
本文介绍了如何检测网格视图的空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何检测网格视图中的空白单元格?,我需要用它来突出显示.所以我做了一个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"; }

更多推荐

如何检测网格视图的空单元格

本文发布于:2023-11-23 04:15:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620052.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   视图   单元格

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!