I am trying to set up a conditional statement for a particular value so that if the value is contained within the data set, it will append m2/kw but when its not it doesn't. I initially had this, but obviously it was still adding the "m2/kw" even if the value wasn't present.

<%#Eval("powerOutput") + "m<sup>2</sup>/kW" %>

So I rewrote it, and it still doesn't work.

<%#Eval("powerOutput").ToString() == "" ?  
Eval("powerOutput") + "m<sup>2</sup>/kW" : "" %>

Edit

<% if (Eval("powerOutput") != null)
                                                                       { %>

                                                                     <%# 
Eval("powerOutput") + "m<sup>2</sup>/kW" %>

                                                                     <% } 
else { %>  <% } %> 

I've now got to this, but I'm now getting an error with

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

1 Answers

0
Captain Wibble On Best Solutions
<%#Eval("powerOutput") + "m<sup>2</sup>/kW" %>

Instead of the above, assuming (as the question isn't explicitly clear) you could do the below if you're treating "powerOutput" as a string and testing for null:

string s = "powerOutput";
if(string.isNullOrEmpty(s)){
    s += "m<sup>2</sup>/kW";
}