Hi all I am having an integer value null
in my table, I would like to bind it to gridview label with 0
when the value is null
, for a nullable
string I write this which works fine but the same with changes didn't work can some one help
嗨,我的表中有一个整型值null,我想把它绑定到gridview标签中,当值为null时,我写的这个可以用,但同样的修改也不行,有人能帮上忙吗
<asp:Label ID="lbl" runat="server" Text='<%#(String.IsNullOrEmpty(Eval("call").ToString()) ? "NULL" : Eval("call"))%>'></asp:Label>
< span lang = en - us style =' font - size: 9.0 pt; font - family:宋体;mso - ascii - font - family: tahoma;“零”:Eval(“调用”))% > " > < / asp:Label >
The same for Integer I write as follows
我写的整数也是一样的
<%# string.IsNullOrEmpty(Eval("send2").ToString()) ? "0" : Convert.ToInt16(Eval("send2")).ToString() %>
< % # string.IsNullOrEmpty(Eval(send2).ToString())?“0”:Convert.ToInt16(Eval(“send2”)).ToString()% >
This didn't worked, any help appreciated
这没有效果,任何帮助都值得赞赏
1 个解决方案
#1
2
To check for the null variables you usually use the System.DBNull
, so you code can be:
要检查空变量,通常使用系统。DBNull,所以代码可以是:
Eval("send2")==System.DBNull ? "0" : Convert.ToInt16(Eval("send2")).ToString()
or aleternative:
或aleternative:
Convert.IsDBNull(Eval("send2")) ? "0" : Convert.ToInt16(Eval("send2")).ToString()
#1
2
To check for the null variables you usually use the System.DBNull
, so you code can be:
要检查空变量,通常使用系统。DBNull,所以代码可以是:
Eval("send2")==System.DBNull ? "0" : Convert.ToInt16(Eval("send2")).ToString()
or aleternative:
或aleternative:
Convert.IsDBNull(Eval("send2")) ? "0" : Convert.ToInt16(Eval("send2")).ToString()