Search code examples
datetimedate-formattingtemplatefield

Show HH:mm 24H format in TemplateField using text property


I'm trying to show a 24 hours format using this line:

Text='<%# Bind("Appointment", "{HH:mm}")

So how it'll be formated for showing for example 16:40 instead 4:40?


Solution

  • if you don't need to bind it, try:

    Text='<%# string.Format("{0:HH:mm}", Eval("Appointment"))%>'

    otherwise i suppose you can update the field value in the OnDataBound event.