in ASP.NET gridview binding two dates. I want to display dd/MM/yyyy
but it displays 10/03/2014 00:00:00
.
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}") %>' />
Blockquote
Eval("Date","{0:dd-MM-yyyy}") %>' />
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 right in the Eval
expression:
Text='<%# Eval("Fromdate", "{0:dd/MM/yyyy}") %>' />
<asp:TemplateField HeaderText="Fromdate">
<ItemTemplate>
<asp:Label ID="lblFromdate" runat="server"
Text='<%#Eval("Fromdate", "{0:dd/MM/yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I achieved it with {0:dd/MM/yyyy}
on the DataFormatString
property of the field
It works well