Tuesday, February 12, 2008

WebNumericEdit and Nullable<decimal>

I was binding Infragistics WebNumericEdit to a Nullable<decimal>. I had to set DataMode of control to NumericDataMode.Decimal. I set Nullable property to true since the value may be missing. (That is also the reason why we store the value as Nullable<decimal>.) It seemed working, but then I noticed that 0 is propagated to data instead of null. So it seems that Nullable<decimal> is not directly supported by WebNumericEdit.

After the short brainstorming, the decision was made to try to override the way how data are provided. Finally, this was sufficient to do:


public class WebNullableNumericEdit
: WebNumericEdit
{
public override object Value
{
get
{
return (this.Nullable &&
this.Text.Equals(this.NullText)) ?
null : base.Value;
}
set { base.Value = value; }
}
}

3 comments:

Anonymous said...

Thanks for your post. It seems like the text of your getter got cutoff in the formatting. What is the rest of the getter statement?

_St said...

I've split the long line of code. Now it should be displayed properly in most browsers.

Amiram said...

Works great! Thanks.