如何修复日期格式ASP .NET绑定列(DataFormatString)?绑定、日期、格式、ASP

2023-09-03 15:51:11 作者:家有儿女

我有一个动态绑定列(对于一个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