inline conditional statement on Eval
inline conditional statement on Eval
(OP)
I am trying to test a dataitem for an empty string and display "N/A" if the string is empty, otherwise display the string. For example, I have tried this:
As suggested by numerous web searches. However, this does not work and produces an "Expression expected." error
Any ideas?
CODE
<%# Eval("code").ToString()=="" ? "N/A" : Eval("code") %>
As suggested by numerous web searches. However, this does not work and produces an "Expression expected." error
Any ideas?
Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneyresource.co.uk
http://www.freemoneysurveys.co.uk
RE: inline conditional statement on Eval
http://stackoverflow.com/questions/9289917/eval-if...
However, my suggestion is to use the correct event depending on the object you are using (i.e. RowDataBound, ItemDataBound, etc.)
This code will make it more clear and easier to maintain.
Also, you can get the code done quicker than trying to figure this out and wasting time on what should be easy, but is not.
RE: inline conditional statement on Eval
In order to get the desired result I can display the string then add an asp:label that checks the length of the dataitem in the visible property:
CODE
still no idea why the original method wouldn't work despite that being a tried and tested method for many others.
Web Development Manager
http://www.freemoneyoff.co.uk
http://www.freemoneyresource.co.uk
http://www.freemoneysurveys.co.uk
RE: inline conditional statement on Eval
Just put a literal or label where you want the code and in the row or itemdatabound, set the text of the literal or label based on your needs.