1

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?

1
  • when you say it doesn't work, what happens...error?...always evaluates to true?...always evaluates to false?
    – Rob D'Oria
    Aug 20, 2011 at 14:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.