Using '<%# Eval(“item”) %>'; Handling Null Value and showing 0 against

前端 未结 11 1673
清酒与你
清酒与你 2020-12-04 12:14

If dataitem is Null I want to show 0

\' runat=\"server\">

        
相关标签:
11条回答
  • 2020-12-04 12:30

    Use IIF.

    <asp:Label ID="Label18" Text='<%# IIF(Eval("item") Is DBNull.Value,"0", Eval("item") %>' 
    runat="server"></asp:Label>
    
    0 讨论(0)
  • 2020-12-04 12:31

    I use the following for VB.Net:

    <%# If(Eval("item").ToString() Is DBNull.Value, "0 value", Eval("item")) %>
    
    0 讨论(0)
  • 2020-12-04 12:36

    It should work as well

    Eval("item") == null?"0": Eval("item");
    
    0 讨论(0)
  • 2020-12-04 12:36

    try this code it might be useful -

    <%# ((DataBinder.Eval(Container.DataItem,"ImageFilename").ToString()=="") ? "" :"<a
     href="+DataBinder.Eval(Container.DataItem, "link")+"><img
     src='/Images/Products/"+DataBinder.Eval(Container.DataItem,
     "ImageFilename")+"' border='0' /></a>")%>
    
    0 讨论(0)
  • 2020-12-04 12:37

    Used a modified version of Jason's answer:

    public string ProcessMyDataItem(object myValue)
    {
      if (myValue.ToString().Length < 1)
      {
         return "0 value";
      }
    
      return myValue.ToString();
    }
    
    0 讨论(0)
  • 2020-12-04 12:39

    I don't know ASP.NET very well, but can you use the ternary operator?

    http://en.wikipedia.org/wiki/Ternary_operation

    Something like: (x=Eval("item")) == Null ? 0 : x

    0 讨论(0)
提交回复
热议问题