In ASP. net2.0, The dataformatstring = "{0: yyyy-mm-dd}" of the gridview does not work. Solution
<Columns>
<Asp: boundfield datafield = "employeeid"/>
<Asp: boundfield datafield = "lastname"/>
<Asp: boundfield datafield = "birthdate" htmlencode = "false" dataformatstring = "{0: yyyy-mm-dd}"/>
</Columns>
Note that the red part must be set to false.
Format -- dataformatstring of Asp.net Data Format
When presenting data, do not present unmodified data to users. For example, if the amount is 10 thousand RMB, If we directly display "10000", the user may be treated as one thousand or 100,000, causing the user to read data. If we make the final modification of 10 thousand yuan into "NT $10,000", it will not only make reading better, but also reduce the chance of making mistakes.
The following figure shows the completed results:
In addition to separating records by color in the DataGrid web control, the preceding data is easier to read by modifying the data of the date, unit price, and subtotal fields. To modify the output of a field, you only need to set the dataformatstring attribute of the field. The syntax is as follows:
Dataformatstring = "{0: Format String }"
We know that {0} In dataformatstring represents the data itself, while the format string after the colon represents the format that we want the data to display; in addition, after the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "12.34" and the format is set to {0: N1}, the output is "12.3 」. The common numeric format is shown in the following table:
Format String data result
"{0: c}" 12345.6789 $12,345.68
"{0: c}"-12345.6789 ($12,345.68)
"{0: d}" 12345 12345
"{0: D8}" 12345 00012345
"{0: e}" 12345.6789 1234568e + 004
"{0: E10 }" 12345.6789 1.2345678900e + 004
"{0: F }" 12345.6789 12345.68
"{0: F0 }" 12345.6789 12346
"{0: g}" 12345.6789 12345.6789
"{0: G7}" 123456789 1.234568e8
"{0: n}" 12345.6789 12,345.68
"{0: N4}" 123456789 123,456,789.0000
"Total: {0: c}" 12345.6789 total: $12345.68
The commonly used date formats are shown in the following table:
format description output format
D simplified Date Format mm/DD/YYYY
D detailed Date Format dddd, Mmmm DD, yyyy
F full format (long date + short time) dddd, Mmmm DD, yyyy hh: mm
F
full Date and Time Format
(long date + long time)
dddd, Mmmm DD, yyyy hh: mm: SS
G General Format (short date + short time) mm/DD/YYYY hh: mm
G General Format (short date + long time) mm/DD/YYYY hh: mm: SS
M, M month/day format mmmm DD
S moderate Date Format yyyy-mm-dd hh: mm: SS
T simplified time format hh: mm
T detailed time format hh: mm: SS
we know that in vs2003 or even vs2005beta, you can use dataformatstring to format the output of boundfield data:
however, you will soon find that dataformatstring does not work in vs2005.
At this time, set htmlencode to false at the same time, and dataformatstring will take effect:
<Asp: boundfield headertext = "displaytext" datafield = "fieldname" dataformatstring = "{0: F2}" htmlencode = "false">
<Itemstyle horizontalalign = "right" width = "60px"> </itemstyle>
<Headerstyle horizontalalign = "right"> </ASP: boundfield>