Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ? 

  + "at" + Convert.ToDateTime(Eval("Modified")).ToShortTimeString()   

: Convert.ToDateTime(Eval("PublishedDate")).ToShortDateString() + " at " + 

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?

share|improve this question
when you say it doesn't work, what happens...error?...always evaluates to true?...always evaluates to false? – Rob D'Oria Aug 20 '11 at 14:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.