Search code examples
c#webformsevalrepeater

Eval can't access a nullable DateTime?


Usually, on a foreach inside the .ascx I access to a nullable DateTime with:

<%=item.DataModifica.Value.ToShortDateString() %>

but if I tried on a Repeater:

<%#Eval("DataModifica.Value.ToShortDateString()").ToString()%>

I get an Exception

System.DateTime' does not contain a property with the name 'Value'

Where am I wrong?


Solution

  • I suggest you change the code like this:

    <%# Convert.ToDateTime(Eval("DataModifica")).ToShortDateString()%>