How to bind a label in gridview from zero to zero from sql server

Hello everyone, I have an integer value null

in my table, I would like to bind it to the gridview label using 0

, when value null

, for a row nullable

I write this which works fine, but the same with changes does not work, can someone 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() %>

It didn't work, any help was appreciated

+3


source to share


1 answer


To check for null variables you usually use System.DBNull

, so the code could be:

Eval("send2")==System.DBNull ?  "0" : Convert.ToInt16(Eval("send2")).ToString()

      



or alternative:

Convert.IsDBNull(Eval("send2")) ? "0" : Convert.ToInt16(Eval("send2")).ToString()

      

+2


source







All Articles