我有一个带有以下代码的动态 BoundField(用于 DetailsView):
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。
有什么方法可以解决这个问题,让它显示“29/04/2013”吗?感谢您的帮助。
最佳答案
您可以将 dataformatstring="{0:M-dd-yyyy}
"属性添加到绑定(bind)字段,如下所示:
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd-M-yyyy}" />
关于c# - 如何修复 ASP .NET BoundField (DataFormatString) 中的日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16357582/