gridview dataformatstring
In the past I became frustrated with the gridview not showing my dates correctly. I don’t want to see the time, I just want the date in very short format. There is this nice property in each column called the dataformatstring which formats the string in that column. If you change it to {0:c} it will format it for currency and {0:d} for a date (or {0:MM-dd-yy}). However, if you don’t change the html encode property then it won’t work. So change it to false when changing your dataformatstring property. Other formats you can use:
| Expression | Description |
| Price: {0:C} | For numeric/decimal data. Displays the literal “Price:” followed by numbers in currency format. The currency format depends on the culture setting specified in the culture attribute on the Page directive or in the Web.config file. |
| {0:D4} | For integer data. Cannot be used with decimal numbers. Integers are displayed in a zero-padded field that is four characters wide. |
| {0:N2}% | For numeric data. Displays the number with 2-decimal place precision followed by the literal “%”. |
| {0:000.0} | For numeric/decimal data. Numbers are rounded to one decimal place. Numbers less than three digits are zero-padded. |
| {0:D} | For date/time data. Displays long date format (“Thursday, August 06, 1996″). Date format depends on the culture setting of the page or the Web.config file. |
| {0:d} | For date/time data. Displays short date format (“12/31/99″). |
| {0:yy-MM-dd} | For date/time data. Displays date in numeric year-month-day format (96-08-06) |

[...] don’t have access to the dataformatstring property like i discussed in this post, but you can set the Text property to a function that you return and format as you like ( [...]
Matt Clingan » Gridview lessons I learnt 3: Access gridview items
September 11, 2007 at 9:47 am