Monday, December 28, 2009

Grid View Data Format String

DataFormatString property of GridView BoundField allows you to specify the format for number values and display them with different styles. You can display the number value as currency, number, decimal or hexadecimal formats.

List of Formats

1. {0:C} Currency format

2. {0:D} Decimal format

3. {0:E} Exponential format

4. {0:F} Fixed format

5. {0:G} General format

6. {0:N} Number format

7. {0:X} Hexadecimal format

8. {0:C2} Currency with 2 decimal places

9. {0:00.00} Number with 2 decimal places

10. {0:000} Number with 2 decimal places

You can also set the GridView Date Formats such as: {0:MM-dd-yyyy} to display the date with month number, day and year, {0:MMM dd, yyyy} to display the date with first three letters of month name, day and year. MMM dd, yyyy, MM-dd-yyyy, MM/dd/yyyy, dd/MM/yyyyy etc as per your requirement.

{0:MM-dd-yyyy HH:mm ss tt} - To display the time format along with date you can use HH for 24Hour, hh for hour, mm for minutes, ss for seconds and tt for AM/PM.

No comments:

Post a Comment