aspnet front end if else statement

Seven price
Seven price used Ask the Experts™
on
This if else statement does not work.
Not sure what is the small modification this needs.

 <%If IIf(Eval("PallCost") Is DBNull.Value, "False", "True") Then%>
                     <%#DataBinder.Eval(Container.DataItem, "CaseCost", "{0:c}")%>
                     <% Else%>
                       <%#DataBinder.Eval(Container.DataItem, "PallCost", "{0:c}")%>
                      <% End If%>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lead Software Engineer
Commented:
Try dropping the quotation marks around False and True and change Is to =.
Or, simplify:
<%If Eval("PallCost") = DBNull.Value Then%>
<%# DataBinder.Eval(Container.DataItem, "CaseCost", "{0:c}") %>
<% Else %>
<%# DataBinder.Eval(Container.DataItem, "PallCost", "{0:c}") %>
<% End If %>
Seven priceFull Stack

Author

Commented:
Error    477    Operator '=' is not defined for types 'Object' and 'System.DBNull'.  


Seven priceFull Stack

Author

Commented:
Oh yeah this is inside a Datalist control
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Most Valuable Expert 2012
Top Expert 2008
Commented:
Try this:

<%# IIf(Eval("PallCost") = DBNull.Value, Format(Eval("CaseCost", "Currency")), Format(Eval("PallCost", "Currency")) %>
Seven priceFull Stack

Author

Commented:
Error    429    Operator '=' is not defined for types 'Object' and 'System.DBNull'.    

Shaun KlineLead Software Engineer
Commented:
Try TheLearnedOne's code with the following modification:

<%# IIf(Eval("PallCost") & String.Empty = String.Empty, Format(Eval("CaseCost", "Currency")), Format(Eval("PallCost", "Currency")) %>
Seven priceFull Stack

Author

Commented:
weird every row comes back with Currency and thats it.
Seven priceFull Stack

Author

Commented:
thanks guys

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial