using if else with eval in aspx page
If you absolutely do not want to use code-behind, you can try conditional operator for this:
<%# ((int)Eval("Percentage") < 50) ? "0 %" : Eval("Percentage") %>
That is assuming field Percentage
contains integer.
Update: Version for VB.NET, just in case, provided by tomasofen:
<%# If(Eval("Status") < 50, "0 %", Eval("Percentage")) %>
<%# (string)Eval("gender") =="M" ? "Male" :"Female"%>
You can try c#
public string ProcessMyDataItem(object myValue)
{
if (myValue == null)
{
return "0 %"";
}
else
{
if(Convert.ToInt32(myValue) < 50)
return "0";
else
return myValue.ToString() + "%";
}
}
asp
<div class="tooltip" style="display: none">
<div style="text-align: center; font-weight: normal">
Value =<%# ProcessMyDataItem(Eval("Percentage")) %> </div>
</div>
If you are trying to bind is a Model class, you can add a new readonly property to it like:
public string FormattedPercentage
{
get
{
If(this.Percentage < 50)
return "0 %";
else
return string.Format("{0} %", this.Percentage)
}
}
Otherwise you can use Andrei's or kostas ch. suggestions if you cannot modify the class itself