Reputation: 301
in ASP.NET gridview binding two dates. I want to display dd/MM/yyyy
but it displays 10/03/2014 00:00:00
.
<asp:TemplateField HeaderText ="Fromdate" >
<ItemTemplate >
<asp:Label ID="lblFromDate" runat="server"
DataFormatString="{0:dd/MM/yyyy}"
HtmlEncode="false"
Text='<%# Eval("Fromdate") %>' />
</ItemTemplate>
</asp:TemplateField>
Upvotes: 18
Views: 82882
Reputation: 22448
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}") %>' />
Upvotes: 25
Reputation: 433
<asp:TemplateField HeaderText="Fromdate">
<ItemTemplate>
<asp:Label ID="lblFromdate" runat="server"
Text='<%#Eval("Fromdate", "{0:dd/MM/yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 2
Reputation: 81
I achieved it with {0:dd/MM/yyyy}
on the DataFormatString
property of the field
It works well
Upvotes: 8
Reputation: 41
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}") %>' />
Upvotes: 4
Reputation: 2646
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**
).
Upvotes: 21