Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider
Gridview DataFormatString not working

I have really been struggling lately with the Gridview.  Most of the time I like to use a label, literal or placeholder in a template column so this does not really affect me.  But I still use a BoundColumn for some fields, like a date or price type thing.  In DataGrids I always was able to use DataFormatString="{0:c} for a currency format and DataFormatString="{0:d}" for a date.

To my surprise this did not work in the GridView.  After a little research I found the GridView has a new BoundField property, HTMLEncode.  You must set HTMLEncode=false to get your DataFormatString expression to be applied to your data.  I did this and voila, property formatting.

Posted: Wednesday, April 19, 2006 4:32 PM

by Chris Love
Filed under: ,

Comments

will said:

I can't seem to get this to work in visual studio 2008. Is anyone else experiencing this issue?
# June 11, 2008 6:58 PM

pfatcat said:

JOY!!!! thanks very much
# August 8, 2008 3:35 PM

Nivedhitha said:

Thank u ,its working.
# August 9, 2008 1:50 AM

Jimmy C said:

How exactly do you set HTMLEncode to false when adding the GridView & Bound Columns dynamically?
# October 16, 2008 1:27 PM

sangam said:

Thank you a lot. I was also facing the same problem. Not it is solved.
# November 11, 2008 6:13 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS