DataFormatString of data Binding use introduction _ Practical Skills

Source: Internet
Author: User
Tags eval
DataFormatString is a lot of asp.net controls have properties, such as the GridView, and so on, the following briefly describes this property.

The dataformatstring property syntax is as follows:

Dataformatstring= ' {0: format string} '

We know that {0} in DataFormatString
Represents the data itself, and the format string after the colon represents the format in which you want the data to appear, and you can specify the number of digits to display for a decimal after the specified format symbol. For example, the original data is
"1.56", if the format is set to {0:n1}, the output is "1.5".

Set BoundField dataformatstring, usually with the following
Dataformatstring= ' {0:c} ' currency, currency format depends on culture settings in current thread
Dataformatstring= "{0:e}" scientific counting method
Dataformatstring= ' {0:p} ' percent
Dataformatstring= "{0:f?}" After a few decimal points
Dataformatstring= "{0:d}" m/d/yyyy as 10/30/2008
Dataformatstring= "{0:f}" Long date, short time. Dddd,mmmm dd,yyyy hh:mm aa such as, Monday, January30, 2008 10:00am
Dataformatstring= ' {0:d} ' long date. Dddd,mmmm dd,yyyy such as: Monday,january 30,2008
Dataformatstring= "{0:f}" Long date, long time dddd,mmmm dd,yyyy HH:mm:ss AA
Dataformatstring= ' {0:s} ' ISO standard time. Yyyy-mm-ddthh:mm:ss, such as: 2008-01-30t10:20:55am
Dataformatstring= ' {0:m} ' month and date MMMM DD, such as January30
Dataformatstring= ' {0:g} ' general format m/d/yyyy HH:mm:ss AA
-----------------------------------------------------------------
format string input 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
Popular date-time formats:
Format Description Output format
D Compact Date format mm/dd/yyyy
D Detail Date format dddd, MMMM DD, yyyy
F Full Format (long date + short time) dddd, MMMM dd, yyyy hh:mm
F
Full Date 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 time format Yyyy-mm-dd HH:MM:SS
T streamlined time format hh:mm
T Verbose time Format HH:mm:ss

<%# String.Format ("{0:yyyy-mm-dd}", Eval ("Effectivedate"))%>
<%# String.Format ("{0:yyyy-m-d}", DataBinder.Eval (Container.DataItem, "effectivedate"))%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.