我的datadsource正在查询表中的varchar列,该列要么为空,要么出现类似“1,2,3,4,5”的内容。
在RowDataBound
事件中我想测试字符串是否为空,所以我可以用图像或其他任何东西替换该字符串。
但
e.Row.Cells[0].Text.Length
为填充的单元格返回9(这是正确的),并为空的返回6。
有人可以向我解释一下吗?它不只是在这一栏中。
答案 0 :(得分:1)
相反,请始终使用String.IsNullOrEmpty
方法检查空字符串。
所以,在你目前的问题中,它将是:
if String.IsNullOrEmpty(e.Row.Cells[0].Text.Trim())
{
// code in here would execute when the Text property is empty/null
}