Tuesday, October 27, 2009

Format DateTime in GridView BoundField or TemplateField

 
Eval has a second parameter which lets you specify the string format. The BoundField has a DataFormatString property:

<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="ExampleDate" runat="server" Text='<%# Eval("ExampleDate", "{0:MM/dd/yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ExampleDate" HeaderText="Example Date 2" DataFormatString = "{0:d}" />



0 comments: