Saturday, February 10, 2007

ASP.NET:DataFormatString Doesn't Work In A GridView If HtmlEncode Is True

So this took me most of my lunch hour to figure out the other day. If you have a gridview and you want to apply formatting to a column then you have to set HtmlEncode to false, by default HtmlEncode is set to true. Of course I thought initially that my super advanced formatting formula ({0:c}) was wrong. A quick Google search found the answer. So below where you see this part HtmlEncode="False" that is the culprit, initiall this will be HtmlEncode="True"

<Columns><asp:BoundField DataField="OrderCost" DataFormatString="{0:c}" HeaderText="OrderCost" HtmlEncode="False" SortExpression="Currency" /></Columns>

I must say that having been away from front-end programming for 5 years I am kind of glad to be back (back is a strong word, I am doing this mostly during lunch and at home because my plate is full with SQL SERVER tasks). But I still have a lot to learn, yep back to n00b status ;-(
Yesterday I was debugging a web service that I wrote in VS 2005. It's kind of cool to see that that works because after you spend time with the SQL Server debugger you would think that something like that would never work

No comments: