Coffee and Code

The Life and Times of Jeff Woodman

Adventures in Databinding

Posted: 10 Feb 2007 06:23 PM ::: 0 Comments ::: permaLink ::: Comments are closed.

Here are a couple of ASP.Net databinding / formatting tricks I've picked up recently:

1. I recently had to bind to a telephone number in a GridView that was stored in the database as a 10-character string. I ran into problems trying to use a DataFormatString property to format the output as (555) 555.5555. Turns out that format strings generally work better with numbers than strings.... duh.

C# Solution: Convert.ToInt64(string).ToString('(000) 000.0000') did the trick. I can't remember where I found the solution, but it's really useful! Sure beats writing a custom method to re-format the number.

2. When using a BoundField to display a DateTime, the DataFormatString property will only work when the HtmlEncode property is set to false.

Filed under: development asp.net tech

Author Bio

Jeff_Blog_Mugshot2.jpg

Jeff Woodman is a web developer living in Santa Fe, New Mexico, USA. He is passionate about coffee, scotch whiskey, and internet technologies. If you see him on the street, you may have to yell to get his attention, because he will most likely have some very loud punk rock playing on his MP3.

Other Places to Find Jeff

Jeff Woodman's Facebook profile
Add to Technorati Favorites Member of W3C Sites dot com
Jeff Woodman on Ma.gnolia.com

last.fm: