Tuesday, June 19, 2012

Remove Commas from WebNumericEdit


When using Infragistics WebNumericEdit, unnecessary commas have to be removed to use this control as a general numeric control. This format is inherited from NumberFormatInfo class, in order to modify this behavior new instance on this class has to be created and set the NumberGroupSeparator property. WebNumericEdit control has the propery called Culture, so a new CultureInfo object can be assign with the required  NumberGroupSeparator. Following code snippet can be use to achieve required behavior.

//C#
using System.Globalization;

// In the page load event
CultureInfo culInfo=new CultureInfo("en-US");  //instance of CultureInfo class

NumberFormatInfo numFromatInfo = new NumberFormatInfo();  // instance of NumberFormatInfo class
numFromatInfo.NumberGroupSeparator= string.Empty;  //set NumberGroupSeparator any string you want

culInfo.NumberFormat=numFromatInfo;

this.WebNumericEdit1.Culture = culInfo; //WebNumericEdit1 is the control to be applied with the new number format

 
This code has to be in the page load event and has to be called in the post backs also .

No comments:

Post a Comment