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);
But somehow, it still shows the wrong format: 2013-04-29T18:15:20.270.
Any way I could fix this for it to show "29/04/2013" instead? Thanks for your help.
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}" />
source: cant format datetime using dataformatstring
Formatting depends on the server's culture setting. If you use en-US
culture, you can use Short Date Pattern like {0:d}
For example, it formats 6/15/2009 1:45:30
to 6/15/2009
You can check more formats from BoundField.DataFormatString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With