如何修复日期格式ASP .NET绑定列(DataFormatString)? [英] How to fix date format in ASP .NET BoundField (DataFormatString)?

查看:140
本文介绍了如何修复日期格式ASP .NET绑定列(DataFormatString)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态绑定列(对于一个DetailsView)具有以下code:

I have a dynamic BoundField (for a DetailsView) with the following code:

BoundField bf1 = new BoundField();
bf1.DataField = "CreateDate";
bf1.DataFormatString = "{0:dd/MM/yyyy}";
bf1.HtmlEncode = false;
bf1.HeaderText = "Sample Header 2";

dv.Fields.Add(bf1);

但不知何故,它仍然显示了格式错误:2013-04-29T18:15:20.270

But somehow, it still shows the wrong format: 2013-04-29T18:15:20.270.

任何办法可以解决这个问题它显示29/04/2013​​呢?感谢您的帮助。

Any way I could fix this for it to show "29/04/2013" instead? Thanks for your help.

推荐答案

您可以添加 dataformatstring ={0:M-DD-YYYY} 属性绑定现场,像这样的:

You could add dataformatstring="{0:M-dd-yyyy}" attribute to the bound field, like this:

<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd-M-yyyy}" />

来源:着格式的日期时间使用dataformatstring

这篇关于如何修复日期格式ASP .NET绑定列(DataFormatString)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆