简体   繁体   English

Datagridview处理smallDatetime数据库字段

[英]Datagridview mangling smallDatetime database field

I am populating a DataTable and then binding this to a GridView control. 我正在填充一个DataTable,然后将其绑定到GridView控件。 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? 但是,边界字段之一是smallDateTime字段,并且在插入到Gridview时会处理数据,如何克服这一问题? I have set the boundfield to have formatting but to no avail the dates are still wrong. 我已将boundfield设置为具有格式,但无济于事,日期仍然是错误的。 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? 当我说错时,我的意思是,例如,一条记录包含日期11/21/2010,在gridview中它显示为3/2/2011 ...我该如何纠正呢?

<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. 您正在格式化为Decimal,而不是SmallDateTime。 See, eg, http://www.csharp-examples.net/string-format-datetime/ . 参见例如http://www.csharp-examples.net/string-format-datetime/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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