Format a numeric string using a numeric composite format
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 DataFormatS开发者_如何学Pythontring="{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?
Try setting HtmlEncode = false on your original BoundField and use your existing dataformatstring.
精彩评论