开发者

GridView OnRowDataBound, Cell's Text.Length

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开发者_JAVA百科

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.


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜