Type of data format settings in the gridview

Source: Internet
Author: User
Formatting Fields
Each boundfield column provides a dataformatstring property that you can use to configure
Appearance of numbers and dates using a format string.
Format strings are generally made up of a placeholder and format indicator, which are
Wrapped inside curly brackets. A typical format string looks something like this:
{0: c}
In this case, the 0 represents the value that will be formatted, and the letter indicates a predetermined
Format style. In this case, C means currency format, which formats a number as a dollar
Figure (So 3400.34 becomes $3,400.34). Here's a column that uses this format string:
<Asp: boundfield datafield = "price" headertext = "price" dataformatstring = "{0: c}"/>
Table 10-3 shows some of the other formatting options for numeric values.
Table 10-3. numeric format strings
Type format string example
Currency {0: C }$ 1,234.50
Brackets indicate negative values: ($1,234.50 ).
Currency sign is locale-specific :(? 1,234.50 ).
Scientific (exponential) {0: e} 1.234.50e + 004
Percentage {0: P> 45.6%
Fixed decimal {0: F ?} Depends on the number of decimal places you
Set. {0: F3} wocould be 123.400. {0: F0} wocould be 123.
You can find other examples in the msdn help. For date or time values, there is also an extensive
List. For example, if you want to write the birthdate value in the format month/day/year (as in
12/30/05), you use the following column:
<Asp: boundfield datafield = "birthdate" headertext = "Birth Date"
Dataformatstring = "{0: mm/DD/yy}"/>
Table 10-4 shows some more examples.
Table 10-4. time and date format strings
Type format string example
Short Date {0: d} m/D/YYYY
(For example: 10/30/2005)
Long Date {0: d} dddd, Mmmm DD, yyyy
(For example: Monday, January 30,200 5)
Long date and short time {0: f} dddd, Mmmm DD, yyyy hh: mm AA
(For example: Monday, January 30,200 5
10: 00 am)
340 chapter 10 ■ rich data controls
Type format string example
Long date and long time {0: f} dddd, Mmmm DD, yyyy hh: mm: SS AA
(For example: Monday, January 30,200 5
10:00:23 am)
ISO sortable standard {0: s} yyyy-mm-dd hh: mm: SS
(For example: 10:00:23)
Month and day {0: m} mmmm dd
(For example: January 30)
General {0: g} m/D/YYYY hh: mm: ss aa (depends on localespecific
Settings)
(For example: 10/30/2002 10:00:23 am)
The format characters are not specific to the gridview. You can use them with other controls,
With data-bound expressions in templates (as you'll see later in this chapter), and as parameters
Using methods. For example, the decimal and datetime types expose their own tostring () Methods
That accept a format string, allowing you to format values manually.

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.