GridView OnRowDataBound,单元格的Text.Length

发布于 2024-10-09 01:53:01 字数 259 浏览 0 评论 0原文

我的 datadsource 正在查询表中的 varchar 列,该列要么为空,要么输出类似“1,2,3,4,5”的内容。

在 RowDataBound 事件中,我想测试字符串是否不为空,以便我可以用图像或其他内容替换该字符串。 但

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

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

有人可以向我解释一下吗?这不仅仅在这一专栏中。

My datadsource is querying the table for a varchar column, that either comes out empty or comes out something like "1,2,3,4,5".

On the RowDataBound event I want to test if the string is not empty so I can substitute that string with an image or whatever.
But

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

returns 9 for the populated Cells (and this is correct), and returns 6 for the empty ones.

Can someone explain this to me? It's not just in this one column.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我老 2024-10-16 01:53:01

相反,请始终使用 String.IsNullOrEmpty< /a> 检查空字符串的方法。

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

if String.IsNullOrEmpty(e.Row.Cells[0].Text.Trim())
{
     // code in here would execute when the Text property is empty/null
}

Instead, always use String.IsNullOrEmpty method to check for empty strings.

So, in your current problem it would be:

if String.IsNullOrEmpty(e.Row.Cells[0].Text.Trim())
{
     // code in here would execute when the Text property is empty/null
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文