Eval check for DBNull doesnt work

心不动则不痛 提交于 2019-11-29 11:10:32

There is a difference between DBNull.Value and null. It is possible the field is returning null.

Try

<%# Eval("Description") == null ? "empty" : "notempty"%>

Also if the field value type is supposed to be string you could do something along the lines of..

<%# (Eval("Description") as string) ?? "empty" %>

Have you tried using this method:

<%# Convert.IsDBNull(Eval("Description") ? "empty" : "notempty"%>

It is not actually storing DBNull at this level. You need to look for null or an empty string which string.IsNullOrEmpty should be enough and will capture both states of null and empty.

<%# string.IsNullOrEmpty(Eval("Description").ToString()) ? "empty" : "notempty"%>  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!