Developing Matt

My Technical Journal

gridview dataformatstring

with one comment

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)
Advertisements

Written by matt

September 4, 2007 at 8:46 am

Posted in Asp.net

One Response

Subscribe to comments with RSS.

  1. […] 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 ( […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: