.Net ramblings
# Thursday, 12 January 2006
Fix: GridView DataFormatString not applied
for some bizarre reason, you have to set HtmlEncode=false on a bound column in a gridview, to get the DataFormatString to work.
i hope this helps somebody else staring at their gridview in disbelief as to why it doesn't work by default!

Thursday, 12 January 2006 16:01:38 (GMT Standard Time, UTC+00:00)  #    Comments [64]  Asp.NetTracked by:
http://vs/devblog/PermaLink,guid,8351df24-b7fc-4b3c-bc2b-5443c30e2cfd.aspx [Pingback]

Tuesday, 17 January 2006 19:52:14 (GMT Standard Time, UTC+00:00)
THANK YOU! I have been trying this for 2 days!!!!!!!!!
Peter Rogers
Thursday, 19 January 2006 15:35:34 (GMT Standard Time, UTC+00:00)
Monday, 23 January 2006 15:41:25 (GMT Standard Time, UTC+00:00)
Excellent work. Couldn't figure this one out for the life of me!
Friday, 27 January 2006 21:32:33 (GMT Standard Time, UTC+00:00)
Friday, 17 February 2006 18:13:43 (GMT Standard Time, UTC+00:00)
I was about to have a brain explosion when I decided to google this problem and found the solution here. Thank you! Why are Microsoft products so full of these glitches?! I must remember that Microsoft documentation is what they would like it to do, not what it does!
Al Reid
Monday, 20 February 2006 22:04:59 (GMT Standard Time, UTC+00:00)
Yes, this is crazy - your post saved me a lot of pain. Thanks!
Wednesday, 22 February 2006 15:15:12 (GMT Standard Time, UTC+00:00)
helped me too. Thanks.

Friday, 24 February 2006 00:50:50 (GMT Standard Time, UTC+00:00)
i love you for this post.
Tuesday, 07 March 2006 13:21:38 (GMT Standard Time, UTC+00:00)
Thanks,Thanks,Thanks!!! from Italy too
Thursday, 16 March 2006 20:37:57 (GMT Standard Time, UTC+00:00)
I set the HtmlEncode=false for all the columns in my GridView, still doesn't work...
Tuesday, 25 April 2006 15:51:41 (GMT Daylight Time, UTC+01:00)
thank you (and google) very much.
Tuesday, 02 May 2006 05:02:21 (GMT Daylight Time, UTC+01:00)
Your post was my first Google hit when searching for this problem. I WOULD HAVE spent several hours fighting this if not for your post. THANK YOU THANK YOU THANK YOU!
Thursday, 04 May 2006 18:01:11 (GMT Daylight Time, UTC+01:00)
Many thanks! I blew nearly an hour trying to get a price field to format as currency... Then I google'd and found your post! (Thank You!)^3
Monday, 15 May 2006 21:15:03 (GMT Daylight Time, UTC+01:00)
THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Monday, 05 June 2006 19:34:37 (GMT Daylight Time, UTC+01:00)
Monday, 26 June 2006 19:09:35 (GMT Daylight Time, UTC+01:00)
Thanks a bunch!!!!
Wednesday, 19 July 2006 17:53:29 (GMT Daylight Time, UTC+01:00)
Thanks very much for this! Was starting to get on my nerves!
Wednesday, 30 August 2006 17:26:58 (GMT Daylight Time, UTC+01:00)
THANK YOU... I was going crazy!!
Wednesday, 30 August 2006 22:15:49 (GMT Daylight Time, UTC+01:00)
Awesome work. After 8 months this post is still getting hits.
THANKS FOR THE SOLUTION. I too, like many others, was going nuts..
Wednesday, 04 October 2006 14:41:16 (GMT Daylight Time, UTC+01:00)
Friday, 20 October 2006 22:06:02 (GMT Daylight Time, UTC+01:00)
Thank you so much. Did anybody ever figure out if there is any logic behind this? Is it a bug?
Saturday, 21 October 2006 00:07:13 (GMT Daylight Time, UTC+01:00)
hi kent. no idea, seems like a bug to me!
Wednesday, 25 October 2006 19:15:58 (GMT Daylight Time, UTC+01:00)
Another butt saved here too - it was driving me batty. Thanks!
Monday, 20 November 2006 19:37:38 (GMT Standard Time, UTC+00:00)
Another bug bites the dust! Thx
Friday, 08 December 2006 10:10:45 (GMT Standard Time, UTC+00:00)
Great find - can't believe it doesn't work by default!!!
Saturday, 09 December 2006 00:20:22 (GMT Standard Time, UTC+00:00)
Thanks for the great tip. I tried for an hour to figure out what was going on. I saw the HTMLEncode property and figured it had nothing to do with the DataFormatString property, go figure...


Tuesday, 19 December 2006 12:13:35 (GMT Standard Time, UTC+00:00)
Mohammad Ajmal Yazdani
Friday, 29 December 2006 18:12:36 (GMT Standard Time, UTC+00:00)
Isn't this something?
Saif Khan
Monday, 22 January 2007 14:54:51 (GMT Standard Time, UTC+00:00)
Thank you!! Microsoft's quirks are endless.
Brian Bouta
Friday, 26 January 2007 19:42:35 (GMT Standard Time, UTC+00:00)
I've been trying to get that to work for 3 days and thought I was gonna kill some one thanks for the help.
Thursday, 08 February 2007 20:09:57 (GMT Standard Time, UTC+00:00)
Over a year old and these two little lines of text are still helping people. Thank!!!
Monday, 12 February 2007 15:10:44 (GMT Standard Time, UTC+00:00)
Thanks mate, these 2lines saved me tons of time.
Wednesday, 21 February 2007 01:59:18 (GMT Standard Time, UTC+00:00)
Did anyone Thank you for this?
Thank you !!!
Friday, 09 March 2007 16:36:10 (GMT Standard Time, UTC+00:00)
Monday, 12 March 2007 20:42:48 (GMT Standard Time, UTC+00:00)
Staring at the GridVeiw indeed.
Bloody MS, I just wasted 1.5 hours on this crap.
Tuesday, 13 March 2007 18:22:46 (GMT Standard Time, UTC+00:00)
Thanks for the fix.

It doesn't work by default because it's MICROCRAP!
Wednesday, 14 March 2007 15:08:00 (GMT Standard Time, UTC+00:00)
THIS DID NOT WORK FOR ME. I have a column of smalldatetime and datetime and neither are affected by this. Here's my code:
<asp:BoundField DataField="StudentBirthDate" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="false" SortExpression="StudentBirthDate" HeaderText="Student DOB" HeaderStyle-CssClass="TableHeaderStyle" HeaderStyle-HorizontalAlign="left" />

I saw a post from Alex on Thursday, March 16, 2006 8:37:57 PM UTC. This fix didn't work for him either. Can someone address this for me please?
Wednesday, 14 March 2007 15:47:38 (GMT Standard Time, UTC+00:00)
hi frankie. your aspx code does work. there must be a problem with the way you are binding the data. can you post that code? cheers. tim.
Wednesday, 14 March 2007 19:26:02 (GMT Standard Time, UTC+00:00)
Thanks for responding to me Tim. You said that my code should work and said their might be something wrong with the way i was binding. That made me think. I'm using a DataAdapter to call a stored procedure. In that stored procedure, i'm returning an XML column. To do this, I had to set the ReturnProviderSpecificTypes property to True before called the Fill method of the adapter. Once I took that property out of the mix, my columns sorted perfectly. Thanks for guiding my thinking.
Wednesday, 14 March 2007 19:36:54 (GMT Standard Time, UTC+00:00)
hi frankie. glad it helped. good luck.
Friday, 30 March 2007 16:10:39 (GMT Daylight Time, UTC+01:00)
Wednesday, 18 April 2007 09:16:25 (GMT Daylight Time, UTC+01:00)
Thank you!! :)
Wednesday, 25 April 2007 18:28:29 (GMT Daylight Time, UTC+01:00)
Thursday, 26 April 2007 13:09:19 (GMT Daylight Time, UTC+01:00)
thanks a lot... its really helpful
Tuesday, 08 May 2007 19:24:31 (GMT Daylight Time, UTC+01:00)
another thanks, ditto to all the exclamations of joy.
Wednesday, 09 May 2007 18:23:57 (GMT Daylight Time, UTC+01:00)
Thanks man, it was helpful
Wednesday, 16 May 2007 20:16:55 (GMT Daylight Time, UTC+01:00)
Pete Skaarup
Saturday, 26 May 2007 00:54:29 (GMT Daylight Time, UTC+01:00)
Thanks dude this was driving me crazy !!!
Wednesday, 13 June 2007 16:45:16 (GMT Daylight Time, UTC+01:00)
you are the man / woman... thanks! stupid microsoft.
Wednesday, 20 June 2007 00:10:48 (GMT Daylight Time, UTC+01:00)
Thanks for a time saver!
Thursday, 21 June 2007 03:05:54 (GMT Daylight Time, UTC+01:00)
Thanks that saved me from loading my gun.
Monday, 02 July 2007 16:54:44 (GMT Daylight Time, UTC+01:00)
Thanks!! it helped mee too . YOU ROCK
Tuesday, 03 July 2007 15:12:33 (GMT Daylight Time, UTC+01:00)

I was getting quite frustrated.

ASP.NET rocks and so does M$
Thursday, 26 July 2007 14:28:57 (GMT Daylight Time, UTC+01:00)
Thanks to you and thanks to Google for helping me find you.
Jim G
Thursday, 09 August 2007 16:18:08 (GMT Daylight Time, UTC+01:00)
Thank you! Thank you! Thank you!
Dave S
Saturday, 11 August 2007 20:12:17 (GMT Daylight Time, UTC+01:00)
Want to add my thanks to the million or so others. Fortunately, thanks to you I didn't spend forever on this problem!

Thursday, 30 August 2007 21:13:09 (GMT Daylight Time, UTC+01:00)
Thanks for the tip, saved me some time!
Wednesday, 19 September 2007 13:37:07 (GMT Daylight Time, UTC+01:00)
Thank you man!
You saved the day.
Friday, 21 September 2007 15:42:09 (GMT Daylight Time, UTC+01:00)
Thanks from Portugal.
Thursday, 08 November 2007 21:56:03 (GMT Standard Time, UTC+00:00)
THANK YOU. I never would have guessed how to fix this.
Friday, 04 January 2008 14:20:20 (GMT Standard Time, UTC+00:00)
THANK YOU. God bless you.
Wednesday, 13 February 2008 14:29:11 (GMT Standard Time, UTC+00:00)
Doug Wolfe
Thursday, 20 November 2008 17:33:08 (GMT Standard Time, UTC+00:00)
Thanks a million.
The wonders of Google and people who share!
Mike Toole
Sunday, 14 February 2010 08:40:02 (GMT Standard Time, UTC+00:00)
I have tried setting HtmlEncodeto false for some columns in my GridView with DataFormatString="{0:N3}"
But its still not working for me. Is there anything else I am missing?

Please help.
Please login with either your OpenID above, or your details below.
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview