Mervin Johnsingh Mervin Johnsingh - 1 month ago 5x
ASP.NET (C#) Question

How can you show the date in a gridview as a date only instead of a datetime?

I am pulling in date values from a sql server database using a gridview and and the date gets converted from

12/12/2009 to 12/12/2009 12:00:00 AM

How do I prevent that from happening ?

Thanks !


You can use the ToString() method with a mask:


UPDATE: Just realized it would be easier in your case to do this in the grid view template

<asp:BoundField DataField="MyDate" DataFormatString="{0:MM/dd/yyyy}" />