The following code correctly formats the date, confirm that your code is equivalent:
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "data_inicio", "{0:dd/MM/yyyy}")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
After receiving some more information per comment, I learned that the property used in the grid column is not of the Datetime type. In order to appear with the desired format, you will need to convert to Datetime and then format again as string
:
<ItemTemplate>
<%# Convert.ToDateTime(Eval("Data")).ToString("dd/MM/yyyy")%>
</ItemTemplate>
But I suggest you do not convert the property to string
and send the DateTime
to the Grid.
What shape is it in? yyyy-mm-dd hh:mm:ss.mmm?
– Jean Gustavo Prates
I’m converting to string at a time so it comes "dd/MM/yyyy 00:00:00", but I need it to display only dd/MM/yyyyy.
– AndreeH