简体   繁体   中英

Datagridview mangling smallDatetime database field

I am populating a DataTable and then binding this to a GridView control. However, one of the boundfields is a smallDateTime field and the data is being mangled on insertion to the Gridview, how do you overcome this? I have set the boundfield to have formatting but to no avail the dates are still wrong. When I say wrong I mean that, for example, a record contains the date 11/21/2010, in the gridview it is shown as 3/2/2011... how do I correct this?

<asp:boundfield datafield="PubDate" headertext="Last Ad Date" 
                SortExpression="PubDate" DataFormatString="{0:d}" 
                HeaderStyle-Wrap="false" ItemStyle-Wrap="false" ItemStyle-Width="75px" HtmlEncode="false">
            </asp:boundfield>

Thanks

You're formatting as Decimal, not SmallDateTime. See, eg, http://www.csharp-examples.net/string-format-datetime/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM