Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Data Formatting Expression

Data Formatting Expression

Data Formatting Expression


I have an ASP.NET datagrid on a page that contains a bound date column.  The Visual Studio DataGrid property builder asks for a "Data Formatting Expression", but I can't get it to accept any syntax I've tried.

The MS help files on bound columns say:

"Using bound columns in a DataGrid Web server control allows you to specify which columns from the data source to display, customize the header and footer for each column, and control sorting."

... note nothing on formatting

When I use dynamic help from the builder I get:
"A .NET framework formatting expression that is applied to the data before it is displayed in the column. This is particularly useful for specifying the format of dates, currency, and numbers, but can be specified for any data."

... not very helpful since there are no examples anywhere that I can find that work.

Can someone please give me some examples to try?  I just want to display the date without the time.



RE: Data Formatting Expression

That's true. There is little or nothing about formating. It took me years to figure it out.

Try putting {0:dd/MM/yyyy} on that field, to show the date with out the time.

Hope this helps.


RE: Data Formatting Expression


That's it!!! Thank You NetAngel!!!

RE: Data Formatting Expression

The .Net stuff has actually simplified that syntax alot.  If you use the databinding property box in a datalist it actually gives you all/some of the formatting expressions.

I actually copied this so that I don't forget so here they are.
General -    {0}
Short Time -    {0:t}
Long Time -    {0:T}
Short Date -    {0:d}
Long Date -    {0:D}
Date & Time -    {0:g}
Full Date -    {0:G}

Number -    {0:N}
Decimal -    {0:D}
Fixed Point -    {0:F}
Currency -    {0:C}
Scientific -    {0:E}
Hexadecimal -    0x{0:X}

That'l do donkey, that'l do
If you are unsure of forum etiquette check here FAQ796-2540

RE: Data Formatting Expression

That's quite usefull when you live in US. Everyone has US Regional Settings.

I live in Portugal. As some people use english and other use portuguese windows versions, and most people don't even bother changing their regional settings, it can cause a LOT of bugs to use those 'shortcuts'. Besides if people look at their application and see a date or time formated in a 'strange' way, they phone immediatly saying the app has a bug and strange chars appear on the middle of the date (it has happened before - most ordinary users don't know the meaning of AM/PM).

I'm just trying to warn to this sort of problem. If you are sure people have their regional settings correct, USE IT. That's great.


RE: Data Formatting Expression

Thanks for that Net Angel.  I didn't realize they were US regional settings.

That'l do donkey, that'l do
If you are unsure of forum etiquette check here FAQ796-2540

RE: Data Formatting Expression

They are not US regional settings. They depend on the computer's regional settings. The problem is that most the people doesn't change them because they don't know or don't care.

Then when they see different formats they don't understand and assume that's a bug.


RE: Data Formatting Expression

Oh so I was right in a way.  Getting confused here but I got it now.
I was at first under the understanding (correctly) that those formatting strings would format depending on regional settings.  Which is why I was suggesting them.  Your application is then more dynamic, displaying different settings to different users.  Assuming they have changed their settings.

Your saying you don't trust people to change their settings and so program your application to display information in a way familiar to the majority of your viewing audience.

Done deal

That'l do donkey, that'l do
If you are unsure of forum etiquette check here FAQ796-2540

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close