To Format the values displayed in GridView:
For BOUNDCOLUMN, use the DataFormatString argument
For TEMPLATECOLUMN, use the second argument of Bind() to format data
Eg:
See complete list of formatting:
Source :http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
For BOUNDCOLUMN, use the DataFormatString argument
For TEMPLATECOLUMN, use the second argument of Bind() to format data
Eg:
See complete list of formatting:
Source :http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
| Format character | Description | Example |
|---|---|---|
| C or c | Displays numeric values in currency format. You can specify the number of decimal places. | Format: {0:C} 123.456 -> $123.46 Format: {0:C3} 123.456 -> $123.456 |
| D or d | Displays integer values in decimal format. You can specify the number of digits. (Although the type is referred to as "decimal", the numbers are formatted as integers.) | Format: {0:D} 1234 -> 1234 Format: {0:D6} 1234 -> 001234 |
| E or e | Displays numeric values in scientific (exponential) format. You can specify the number of decimal places. | Format: {0:E} 1052.0329112756 -> 1.052033E+003 Format: {0:E2} -1052.0329112756 -> -1.05e+003 |
| F or f | Displays numeric values in fixed format. You can specify the number of decimal places. | Format: {0:F} 1234.567 -> 1234.57 Format: {0:F3} 1234.567 -> 1234.567 |
| G or g | Displays numeric values in general format (the most compact of either fixed-point or scientific notation). You can specify the number of significant digits. | Format: {0:G} -123.456 -> -123.456 Format: {0:G2} -123.456 -> -120 |
| N or n | Displays numeric values in number format (including group separators and optional negative sign). You can specify the number of decimal places. | Format: {0:N} 1234.567 -> 1,234.57 Format: {0:N4} 1234.567 -> 1,234.5670 |
| P or p | Displays numeric values in percent format. You can specify the number of decimal places. | Format: {0:P} 1 -> 100.00% Format: {0:P1} .5 -> 50.0% |
| R or r | Displays Single, Double, or BigInteger values in round-trip format. | Format: {0:R} 123456789.12345678 -> 123456789.12345678 |
| X or x | Displays integer values in hexadecimal format. You can specify the number of digits. | Format: {0:X} 255 -> FF Format: {0:x4} 255 -> 00ff |
| d | Short date pattern. | Format: {0:d} 6/15/2009 1:45:30 PM -> 6/15/2009 |
| D | Long date pattern. | Format: {0:D} 6/15/2009 1:45:30 PM ->Monday, June 15, 2009 |
| f | Full date/time pattern (short time). | Format: {0:f} 6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45 PM |
| F | Full date/time pattern (long time). | Format: {0:F} 6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45:30 PM |
| g | General date/time pattern (short time). | Format: {0:g} 6/15/2009 1:45:30 PM -> 6/15/2009 1:45 PM |
| G | General date/time pattern (long time). | Format: {0:G} 6/15/2009 1:45:30 PM -> 6/15/2009 1:45:30 PM |
| M or m | Month/day pattern. | Format: {0:M} 6/15/2009 1:45:30 PM -> June 15 |
| O or o | Round-trip date/time pattern. | Format: {0:o} 6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000 |
| R or r | RFC1123 pattern (for information, see DateTimeFormatInfo.RFC1123Pattern). | Format: {0:R} 6/15/2009 1:45:30 PM -> Mon, 15 Jun 2009 20:45:30 GMT |
| s | Sortable date/time pattern. | Format: {0:s} 6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30 |
| t | Short time pattern. | Format: {0:t} 6/15/2009 1:45:30 PM -> 1:45 PM |
| T | Long time pattern. | Format: {0:T} 6/15/2009 1:45:30 PM -> 1:45:30 PM |
| u | Universal sortable date/time pattern. | Format: {0:u} 6/15/2009 1:45:30 PM -> 2009-06-15 20:45:30Z |
| U | Universal full date/time pattern. | Format: {0:U} 6/15/2009 1:45:30 PM -> Monday, June 15, 2009 8:45:30 PM |
| Y or y | Year month pattern. | Format: {0:Y} 6/15/2009 1:45:30 PM -> June, 2009 |
No comments:
Post a Comment