<%# Eval("FeeStatus") == DBNull.Value OR 0 ? "UnPaid" : "Paid" %>
I simply want to say IF FeeStatus is null or 0 than print Unpaid .. what is syntax? and what this condition is called i mean I am searching on net but don't know what to write ?
<%# Eval("FeeStatus") == DBNull.Value OR 0 ? "UnPaid" : "Paid" %>
I simply want to say IF FeeStatus is null or 0 than print Unpaid .. what is syntax? and what this condition is called i mean I am searching on net but don't know what to write ?
This is probably kept most readable by creating a helper function:
public bool IsPaid(object feeStatus) {
return feeStatus != DBNull.Value && !(bool)feeStatus;
}
Then you can write:
<%# !IsPaid(Eval("FeeStatus")) ? "UnPaid" : "Paid" %>
C# doesn't have any native x == (y or z)
form that translates to x == y || x == z
except only evaluating x
once, you need either a helper function or a helper variable for that.
You could write it out in full, if you don't mind calling Eval
twice:
<%# Eval("FeeStatus") == DBNull.Value || !(bool)Eval("FeeStatus")? "UnPaid" : "Paid" %>
but this is harder to understand.
But if your FeeStatus
is known to be one of DBNull.Value
, false
, or true
, instead of comparing to DBNull.Value
and false
, you could just compare to true
:
<%# Eval("FeeStatus").Equals(true) ? "Paid" : "UnPaid" %>
Close but no cigar.
<%# Eval("FeeStatus") == DBNull.Value || (int) Eval("FeeStatus") == 0 ? "UnPaid" : "Paid" %>
OR
<%# new object[]{ DBNull.Value, 0 }.Contains(Eval("FeeStatus")) ? "UnPaid" : "Paid" %>
There is no OR
operator in C#. Not to mention its not clear how you expect the OR
operator would work in boolean logic.
Oh man...okay turns out you want this abomination.
<%# Eval("FeeStatus") as bool? ?? false ? "Paid" : "UnPaid" %>