If dataitem is Null
I want to show 0
<asp:Label ID="Label18" Text='<%# Eval("item") %>' runat="server"></asp:Label>
How can I accomplish this?
If dataitem is Null
I want to show 0
<asp:Label ID="Label18" Text='<%# Eval("item") %>' runat="server"></asp:Label>
How can I accomplish this?
I use the following for VB.Net:
Try replacing
<%# Eval("item") %>
with<%# If(Eval("item"), "0 value") %>
(or<%# Eval("item") ?? "0 value" %>
, when using C#).I have tried this code and it works well for both null and empty situations :
Used a modified version of Jason's answer:
I'm using this for string values:
You can also use following for nullable values:
Also if you're using .net 4.5 and above I suggest you use strongly typed data binding:
Moreover, you can use (x = Eval("item") ?? 0) in this case.
http://msdn.microsoft.com/en-us/library/ms173224.aspx