Date format without time in ASP.NET Gridview

According to this article on MSDN the DataFormatString attribute has a limited number of variants for DateTime data.

What you are looking for is:

DataFormatString="{0:d}"

which is the short date pattern.

In order to get the dd/MM/yyyy format, you need to also set your culture info properly (for example to **en-GB**).


DataFormatString is a property of BoundField control and doesn't affect any other control. You can specify the format in an Eval expression:

Text='<%# Eval("Fromdate", "{0:dd/MM/yyyy}") %>' />

I achieved it with {0:dd/MM/yyyy} on the DataFormatString property of the field

It works well

Tags:

C#