Reputation: 8636
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
<asp:Label ID="lbl" runat="server" Text='<%#(String.IsNullOrEmpty(Eval("call").ToString()) ? "NULL" : Eval("call"))%>'></asp:Label>
The same for Integer I write as follows
<%# string.IsNullOrEmpty(Eval("send2").ToString()) ? "0" : Convert.ToInt16(Eval("send2")).ToString() %>
This didn't worked, any help appreciated
Upvotes: 3
Views: 2322
Reputation: 66641
To check for the null variables you usually use the System.DBNull
, so you code can be:
Eval("send2")==System.DBNull ? "0" : Convert.ToInt16(Eval("send2")).ToString()
or aleternative:
Convert.IsDBNull(Eval("send2")) ? "0" : Convert.ToInt16(Eval("send2")).ToString()
Upvotes: 2