I have an SPGridView with a list as its source. I currently have it sorting first by published date, or if that is null, by modified date. The problem is that on the list view I need to put Posted on DD/MM/YY at HH:MM in each row. I came up with this monsterous evaluation (which is all on one line in the markup):
Posted on
<%# Eval("PublishedDate") == null ?
Convert.ToDateTime(Eval("Modified")).ToShortDateString()
+ "at" + Convert.ToDateTime(Eval("Modified")).ToShortTimeString()
: Convert.ToDateTime(Eval("PublishedDate")).ToShortDateString() + " at " +
Convert.ToDateTime(Eval("PublishedDate")).ToShortTimeString()%>
Anyway, It doesn't work. If I remove the ternary operator and just go with one option, it works. While googling about this I saw that it is perfectly valid to use the ternary inside of <%# %>. What am I doing wrong?