ASP.NET date format gridview
Last modified: July 01, 2021We need to put AutoGenerateColumns equals to false
so that it does not automatically populate GridView. We have to use ItemTemplate to put our date (in format).
<asp:GridView ID="GridViewMovie" DataKeyNames="Id" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Rating" HeaderText="Rating" SortExpression="Rating" />
<asp:TemplateField HeaderText="DateReleased">
<ItemTemplate>
<%#Eval("DateReleased", "{0:dd-MM-yyyy}") %> <!--we format to dd-MM-yyyy-->
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>