how to detect grid view empty cell ? I need it for highlighting. So I made a css
如何检测网格视图空单元?我需要它来突出显示。所以我做了一个CSS
.RedColored
{
background: FF0000;
}
and trying to appear it to empty GV cells this way :
并尝试以这种方式将其显示为清空GV细胞:
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.
但我似乎没有空单元格,即使我已经尝试了Text ==“”,Cell [i] == null,Cell [i] .ToString()==“”并没有任何帮助。
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 :P Finally : solved with this code :` e.Row.Cells[0].CssClass = "wide";
但是!!!它甚至没有帮助,它没有WHEN,但是当(if)找不到空单元时:P最后:用这个代码解决:`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;
}
}`
4 个解决方案
#1
1
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():
要测试单元格,您应该使用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";
}
#2
3
"When a bound GridView cell contains no data, ASP.NET fills it with Hence the length of 6"
“当绑定的GridView单元格不包含任何数据时,ASP.NET会将其填充为”因此长度为6“
http://bytes.com/topic/asp-net/answers/768857-how-check-if-cell-gridview-empty
#3
1
I have wrote a utility function for this in the past, it is in VB.NET but should be pretty straighforward to convert to C#
我以前为此编写了一个实用程序函数,它在VB.NET中,但转换为C#应该非常简单
Public Shared Function IsCellBlank(ByVal cell As DataGridViewCell) As Boolean
公共共享函数IsCellBlank(ByVal cell As DataGridViewCell)作为布尔值
If (cell.Value Is Nothing) Then Return True End If If (cell.Value.ToString().Length = 0)
Then
Return True End If If (cell.Value.GetType().Name = "DBNull") Then Return True End If Return False End Function
#4
1
Try this:
protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[3].Text.Equals(" "))
{
e.Row.Cells[3].BackColor = Color.Red;
}
}
}
#1
1
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():
要测试单元格,您应该使用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";
}
#2
3
"When a bound GridView cell contains no data, ASP.NET fills it with Hence the length of 6"
“当绑定的GridView单元格不包含任何数据时,ASP.NET会将其填充为”因此长度为6“
http://bytes.com/topic/asp-net/answers/768857-how-check-if-cell-gridview-empty
#3
1
I have wrote a utility function for this in the past, it is in VB.NET but should be pretty straighforward to convert to C#
我以前为此编写了一个实用程序函数,它在VB.NET中,但转换为C#应该非常简单
Public Shared Function IsCellBlank(ByVal cell As DataGridViewCell) As Boolean
公共共享函数IsCellBlank(ByVal cell As DataGridViewCell)作为布尔值
If (cell.Value Is Nothing) Then Return True End If If (cell.Value.ToString().Length = 0)
Then
Return True End If If (cell.Value.GetType().Name = "DBNull") Then Return True End If Return False End Function
#4
1
Try this:
protected void grdList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[3].Text.Equals(" "))
{
e.Row.Cells[3].BackColor = Color.Red;
}
}
}