You are missing parentheses around a conditional expression.
Try this instead:
string text = "<option value=\"" + cuID.Value + "\">" + cuName + " (" + (cuEmpID == "" ? "-" : cuEmpID) + ")" + "</option>"; htmlResp.Append(text);
As for why the missing parentheses caused this ... What an interesting question!
To answer this, let me simplify the source code a bit:
string text = ">>>" + cuEmpID == "" ? "-" : cuEmpID + "<<<";
What happens because the conditional expression uses ">>>" + cuEmpID == "" as a condition. This is not equal to "", so the right side of the conditional expression is used, namely the cuEmpID + "<<<" , which gives the result that we see.
You really have to simplify the expression, for example:
string normalisedEmpID = cuEmpID == "" ? "-" : cuEmpID; string text = string.Format ( "<option value=\"{0}\">{1} ({2})</option>", cuID.Value, cuName, normalisedEmpID );
source share