The format that is commonly used to bind data to a gridview.

Source: Internet
Author: User

Form

Syntax

Result

Note

Number

{0: N2}

12.36

 

Number

{0: N0}

13

 

Currency

{0: C2}

$12.36

 

Currency

{0: C4}

$12.3656

 

Currency

"¥ {0: N2 }"

¥12.36

 

Scientific notation

{0: E3}

1.23e + 001

 

Percentage

{0: p}

12.25%

P and P present the same.

Date

{0: d}

November 25, 2006

 

Date

{0: d}

2006-11-25

 

Date

{0: f}

November 25, 2006

 

Date

{0: f}

November 25, 2006 10:30:00

 

Date

{0: s}

2006-11-25 10:30:00

 

Time

{0: t}

10:30:00

 

When operating in the gridview, pay attention to the following aspects (take {0: d} as an example)

1. If the column to be bound is of the boundfiled type (as shown below)

<Asp: boundfield datafield = "SJ" headertext = "time" readonly = "true" dataformatstring = "{0: d}"/>

The displayed format is 0:00:00 to achieve the desired effect.

2. The column to be bound must be the template column as follows: in this way, we can see the expected effect: 2006-11-25

<Asp: templatefield headertext = "time">

<Edititemtemplate>

<Asp: Label id = "label1" runat = "server" text = '<% # eval ("SJ", "{0: d }") %> '> </ASP: Label>

</Edititemtemplate>

<Itemtemplate>

<Asp: Label id = "label2" runat = "server" text = '<% # BIND ("SJ", "{0: d }") %> '> </ASP: Label>

</Itemtemplate>

</ASP: templatefield>

The format that is commonly used to bind data to a gridview.

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.