Implement custom time, currency, and other string formats in the gridview

Source: Internet
Author: User
Method 1:
<Asp: gridview id = "gridview1" runat = "server">
<Columns>
<Asp: boundfield datafield = "creationdate"
Dataformatstring = "{0: M-dd-yyyy }"
Htmlencode = "false"
Headertext = "creationdate"/>
</Columns>
</Asp>
Set htmlencode to false.
Method 2:
Use template Columns
<Asp: gridview id = "gridview3" runat = "server">
<Columns>
<Asp: templatefield headertext = "creationdate">
<Edititemtemplate>
<Asp: Label id = "label1" runat = "server"
TEXT = '<% # eval ("creationdate", "{0: M-dd-yyyy}") %>'>
</Asp>
</Edititemtemplate>
<Itemtemplate>
<Asp: Label id = "label1" runat = "server"
TEXT = '<% # BIND ("creationdate", "{0: M-dd-yyyy}") %>'>
</Asp>
</Itemtemplate>
</Asp>
</Columns>
</Asp>

Appendix-common formatting formula:
{0: c} currency;
{0: D4} the integer is displayed in the 4-character width field filled with 0;
{0: 000. 0} rounded to the decimal point to retain the nth valid number;
{0: N2} Keep two valid decimal places; {0: N2} % keep two valid decimal places plus a percent sign;
{0: d} long date; {0: d} short date; {0: yy-mm-dd} For example 07-3-25; {0: yyyy-mm-dd} example: 2007-3-25

Related Article

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.