Tuesday, November 11, 2008

Asp.net GridView DataFormatString not working

People have reported that the DataFormatString property of asp.net GridView used for formatting price {0:c} or date {0:d} etc is not working in asp.net GridView. However, they say, it works in DataGrid control. Yeah, I had the same problem. I wished to display the date in the format MM/DD/YYYY, e.g. 11/11/2008. And naturally I used the DataFormatString="{0:d}" in my GridView's property. But it did not work. So I had to go a little further. After some time, I came to know the reason.

Why asp.net GridView's DataFormatString is not working in asp.net 2.0?

It has been reported that the GridView control performs the html encoding before the data is formatted according to the DataFormatString. So the simple workaround is to disable the HtmlEncode property of the column in which DataFormatString is being applied.

Now it works fine. Let me force that the same trick works for asp.net DetailsView control also. Happy Programming!


Anonymous said...

This worked for me

Anonymous said...


Post a Comment

Hope you liked this post. You can leave your message or you can put your valuable suggestions on this post here. Thanks for the sharing and cooperation!

Popular Posts

Recent Articles