Hi,
I have a page with a WebNumericEdit control and a grid....
a column with diferent values (1 ... 0,25 ... 0,345678952315 ... 1,05498 ... 400 ...)
I want that when the user enters the page,
the values presented to him be with, let's say, max of 3 decimal digits (in the example above 1 ... 0,25 ... 0,345 ... 1,054 ... 400) and when he enters edit mode, the hole cell value be showed to him...That's the normal behaviour off the grid by using it's column format property..
But I also need that the user see the cell value with a certain cultureInfo....I do that by using a NumericEditControl and then the column shows the hole value all the time.
Any Ideas???
Obs.: I have the following code in UltraWebGrid initialize Layout for the user to see the number formated in his CultureInfo when in editMode:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("pt-BR"); ci.NumberFormat.NumberDecimalSeparator = ",";
//Set this property because if not, only 2 digits are showned
ci.NumberFormat.NumberDecimalDigits = 20; WebNumericEdit1.NumberFormat = ci.NumberFormat;
UltraWebGrid1.DisplayLayout.AllowUpdateDefault = Infragistics.WebUI.UltraWebGrid.AllowUpdate.Yes; UltraWebGrid1.Columns[1].Type = Infragistics.WebUI.UltraWebGrid.ColumnType.Custom; UltraWebGrid1.Columns[1].EditorControlID = WebNumericEdit1.UniqueID;
Still no solution or workaround for this?
As Tony mentioned that if embedded editor provider is used, then editing and rendering is defined not by grid, but by editor. So, the only way around is to modify that editor (better to say: hack into its logic). All aspects of "embedded" features are defined byInfragistics.WebUI.Shared.IProvidesEmbeddableEditor. There are few methods on server and few methods on client. You will be interested in the getRenderedValue and RenderValue members.
To adjust value provided by editor after user edited cell, you need to override the getRenderedValue member function. Example below will limit number of digits after dot to 1.
<script type="text/javascript">function WebNumericEdit1_Initialize(oEdit, text){ oEdit.myOldGetRenderedValue = oEdit.getRenderedValue; oEdit.getRenderedValue = function(v) { var val = this.myOldGetRenderedValue(v); var dot = val.indexOf('.'); if(dot > 0 && dot + 2 < val.length) val = val.substring(0, dot + 2); return val; }}</script>
To support rendering of initial values is more complex. You need to remove WebNumericEdit from aspx, extend it and override its RenderValue. Below is example:
public partial class MyPage : System.Web.UI.Page{ // all your codes here
private MyWebNumericEdit WebNumericEdit1; protected override void OnInit(EventArgs e) //or //protected void Page_Load(object sender, EventArgs e) { this.WebNumericEdit1 = new MyWebNumericEdit(); this.WebNumericEdit1.ID = "WebNumericEdit1"; this.WebNumericEdit1.ClientSideEvents.Initialize = "WebNumericEdit1_Initialize"; this.Form.Controls.Add(this.WebNumericEdit1); }}
internal class MyWebNumericEdit : Infragistics.WebUI.WebDataInput.WebNumericEdit{ public override string RenderValue(object value) { string val = base.RenderValue(value); int dot = val.IndexOf('.'); if(dot > 0 && dot + 2 < val.Length) val = val.Substring(0, dot + 2); return val; }}
I need to receive the same formatting of numbers in WebNumericEdit, but without grid. I try your recommendations. But it is unsuccessful: works function WebNumericEdit1_Initialize() only. There are no calls of the function RenderValue() in the creation of page and function getRenderedValue() on client.
May be this solution work for embedded editors only?
May be exists any solution for simple WebNumericEdit ?
I am using NetAdvantage for .Net 2007 Volume 1 CLR 2.
I tried to customize format/pattern/etc of WebNumericEdit - but unsuccessfully.
I am sorry for not clear explains of the problem.
I have a page with wNumEdit1 as WebNumericEdit control.
For example, user inputs number 123.123456 into wNumEdit1 and go to next field. I need that the text in the wNumEdit1 field shown as a 123.1235 ( rounded to 4 digits ) , but value remains = 123.123456.
If the user moves in the wNumEdit1 field that it again sees whole value 123.123456 for editing.
That is, control should show number in two formats. In "show" mode - as formated rounded number, in "edit" mode - whole number.
Now I try to format a wNumEdit1 control's text in onblur handler:
function WebNumEdit_TextFormat(oEdit) { // onblur handler setTimeout("FormatNumText('"+oEdit.ID+"');", 100); } function FormatNumText(numEdID) { var numEdCtrl = igedit_getById(numEdID); if (numEdCtrl) { var valTxt = numEdCtrl.text; var dot = valTxt.indexOf('.'); if(dot > 0 && dot + 5 < valTxt.length) { valTxt = numToStrFormat(numEdCtrl.value, 4); numEdCtrl.text = valTxt; numEdCtrl.repaint(); } } }
I will be grateful for any ideas.
To customize format/pattern/etc of WebNumericEdit you do not need to override anything. You can create a NumberFormatInfo object with disired properties and set it to NumberFormat property of control (similar to codes in the very first email or NetAdvantage samples related to culture formats).