DataFormatString not working on a GridView DateTime column

R

Rob Roberts

I have a GridView that is bound to a collection of DateTimes (i.e. -
Collection<DateTime>). I have a BoundField in the GridView, and its
DataField is set to the DateTime's Date property, and the DataFormatString
is set to "{0:d}" in order to display the date in short date format (without
the time). But the DataFormatString doesn't seem to have any effect. The
DateTime gets displayed with the time.

I have another GridView that is bound to a collection of business objects,
and the business objects have a DateTime property. One of the columns in
the GridView has a BoundField that uses this DateTime property as its
DataField. In this case, the "{0:d}" DataFormatString works as it should.
(The DateTime is displayed in short date format, without the time.) So it
works in this case, but not when I have the GridView bound to a collection
of DateTimes.

I've worked around the problem by using the RowDataBound event to manually
trim the time from the end of the cell's text, but that's a kludgy
workaround. Does anyone know why the DataFormatString isn't working
correctly in this case?

Thanks in advance,
--Rob Roberts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top