Introduction to ASP. NET string formatting

Source: Internet
Author: User

What is the formatting Method for ASP. NET strings? What is the usage of the ASP. NET string formatting and display method? So next let's take a look at what exactly is there?

 
 
  1. Date. ToString ("MM-yyyy", DateTimeFormatInfo. InvariantInfo)

And so on.

ASP. NET string formatting 1. Date formatting method when binding:

 
 
  1. ﹤ASP:BOUNDCOLUMN DATAFIELD= "JoinTime "   
  2. DATAFORMATSTRING= "{0:yyyy-MM-dd} " ﹥    
  3. ﹤ITEMSTYLE WIDTH= "18% " ﹥ ﹤/ITEMSTYLE ﹥    
  4. ﹤/ASP:BOUNDCOLUMN ﹥ 

ASP. NET string formatting 2. Data controls such as DataGrid/DataList:

 
 
  1. e.Item.Cell[0].Text = Convert.ToDateTime(  
  2. e.Item.Cell[0].Text).ToShortDateString(); 

ASP. NET String formatting 3. Convert the date display format with the String type:

 
 
  1. String.Format( "yyyy-MM-dd ",yourDateTime); 

ASP. NET string formatting 4. Convert the date display format using the Convert method:

 
 
  1. Convert. ToDateTime ("2005-8-23"). ToString
  2. ("YyMMdd", System. Globalization.
  3. DateTimeFormatInfo. InvariantInfo );// Supports traditional databases 

ASP. NET string formatting 5. Convert the date display format using the ToString method directly:

 
 
  1. DateTime.Now.ToString("yyyyMMddhhmmss");   
  2. DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") 

ASP. NET string formatting 6. display only the year and month

 
 
  1. DataBinder.Eval(Container.DataItem,"starttime","{0:yyyy-M}") 

ASP. NET string formatting 7. display all parts of the time, including: year, month, day, hour, minute, and second

 
 
  1. <Asp: BoundColumn DataField ="Receipt time"HeaderText ="Receipt time"
  2. DataFormatString ="{0: yyyy-MM-dd HH24: mm: ss }">
  3. </Asp: BoundColumn>

The basic content of the ASP. NET string formatting and display method is introduced here. I hope to help you understand and learn ASP. NET string formatting and display methods.

  1. In-depth research on Repeater controls: Maximum Flexibility
  2. Getting started with DataList controls
  3. Exploring the operation mechanism of the DataGrid Web Control
  4. Discuss the similarity between ASP. NET data Web controls
  5. Transformation from traditional ASP to ASP. NET: Understanding controls

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.