Ternary operator in aspx page

Developer

Hi all I would like to use ternary operator in aspx page. I am having two public variables in my aspx.cs file as follows

public string currency = "INR";
public decimal amount = 100;

I would like to frame the html tags based on my currency, currently I am doing like this

<% if (currency != "INR")
  {%>
     <span>$<%=amount%></span>
  <%}
  else
  { %>
    <span<%=amount%></span>
  <%} %>

I would like to do it one line

<span><% if (currency != "INR") %> $ amout <% : %> </span>

But I am getting error as Invalid expression term ':' so can some one help me if this is possible

bytecode77

A tenary operator works without an if. It looks as follows:

booleanExpression ? trueValue : falseValue

But you can't treat ASP.NET like PHP, so you will have to put this in one <% %> wrapper

<span><%= (currency != "INR" ? "$" : "") + amount %></span>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related