-1

我的数据源正在查询表中的 varchar 列,该列要么是空的,要么是像“1,2,3,4,5”这样的东西。

RowDataBound我想测试字符串是否不为空的情况下,我可以用图像或其他内容替换该字符串。但

e.Row.Cells[0].Text.Length  

为填充的单元格返回 9(这是正确的),为空的单元格返回 6。

谁可以给我解释一下这个?它不只是在这一列。

4

1 回答 1

1

相反,始终使用String.IsNullOrEmpty方法来检查空字符串。

因此,在您当前的问题中,它将是:

if String.IsNullOrEmpty(e.Row.Cells[0].Text.Trim())
{
     // code in here would execute when the Text property is empty/null
}
于 2010-12-26T18:05:03.467 回答