A A
RSS

DataFormatString not working with date format in GridView

Tue, May 22, 2007

Programming

I set the DataFormatString to {0:d} and also tried {0:MM-dd-yyyy} as several forums and articles suggested; but it still wouldn’t work and kept on displaying the entire string including the time. It turns out, all I had to do is add HtmlEncode=”false”.

<asp:GridView ID=”gridItems” runat=”server” AutoGenerateColumns=”False” DataKeyNames=”ItemId”
DataSourceID=”MyItemsDataSource” Width=”100%”>
<Columns>
<asp:BoundField DataField=”Title” HeaderText=”Title” SortExpression=”Title” />
<asp:BoundField DataField=”Status” HeaderText=”Status” SortExpression=”Status” />
<asp:BoundField DataField=”DateCreated” HeaderText=”Listed on” SortExpression=”DateCreated”
DataFormatString=”{0:d}” HtmlEncode=”false” />
</Columns>
</asp:GridView>

Tags: , ,

blog comments powered by Disqus
Advertise Here

What I'm Doing...

Yonkly Open Source

Sign up for my newsletter

powered by MailChimp!

Cyber Identity