tags:

views:

26

answers:

1

I've just encountered an interesting problem in a standard BoundField in a GridView. The field is for EmployeeCode, which is purely numeric, but stored in a character column in the database. The DataFormatString="{0:00000}" attribute on the BoundField doesn't work, as I assume that format is only for numeric values.

To work around this, I had to use a TemplateField, and bind the text value using the attribute Text='<%# PadNumericString(Eval("EmployeeCode").ToString(), 5) %>'. Is there no simpler way of doing this?

A: 

Try setting HtmlEncode = false on your original BoundField and use your existing dataformatstring.

RandomNoob
I tried that and it doesn't work. I ended up formatting the string in the DB view that populates the grid: "right('00000' + ar.EmployeeCode, 5) EmployeeCode"
ProfK