SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.