Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Formatting Expression 2

Status
Not open for further replies.

JGresko

Programmer
Apr 24, 2002
86
US

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.

Thanks,

Judy



 
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. NetAngel
 
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}
Dates
---------------------------------
Short Time - {0:t}
Long Time - {0:T}
Short Date - {0:d}
Long Date - {0:D}
Date & Time - {0:g}
Full Date - {0:G}

Numbers
--------------------------------
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
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
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.
NetAngel
 
Thanks for that Net Angel. I didn't realize they were US regional settings. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
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.
NetAngel
 
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
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top