Friday, December 7, 2007

Limited formatting in DataBinder.Eval

I've been requested to display special text ("n.a.") in the case that evaluated expression is not there (is null). I've intended to provide my custom format provider that would work like requested. Unfortunately, DataBinder.Eval does not allow you to provide your custom format provider even though string.Format is called internally that can handle it.

I've solved it by creating my custom control inherited from Label that provides special text when the Text property is null or empty on rendering. I would consider the ability to provide my custom formatter more convenient and somewhat smarter, however.