4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 09 Jun 2009, 05:54 AM
Hello Jessie,
You can set the DataFormatString for the boundcolumn such that it displays only two digits after the decimal point.
aspx (To display the required format when the column is in Normal mode):
c#(To display the required format for the TextBox when the column is in EditMode):
Thanks
Princy.
You can set the DataFormatString for the boundcolumn such that it displays only two digits after the decimal point.
aspx (To display the required format when the column is in Normal mode):
| <telerik:GridBoundColumn HeaderText="Value" UniqueName="Value" |
| DataFormatString="{0:N2}" DataField="Value"> |
| </telerik:GridBoundColumn> |
c#(To display the required format for the TextBox when the column is in EditMode):
| protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| TextBox tb = (e.Item as GridEditableItem)["Value"].Controls[0] as TextBox; |
| string dataFormatString = (RadGrid2.MasterTableView.GetColumn("Value") as GridBoundColumn).DataFormatString; |
| tb.Text = String.Format(dataFormatString, double.Parse(tb.Text)); |
| } |
| } |
Thanks
Princy.
0
Jessie
Top achievements
Rank 1
answered on 09 Jun 2009, 02:15 PM
Hi Princy,
Thanks for the replay. What I mean is not only for display, but also for prevent the user inputting more than 2 digits after the dedimal point.
Jessie
Thanks for the replay. What I mean is not only for display, but also for prevent the user inputting more than 2 digits after the dedimal point.
Jessie
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jun 2009, 09:32 AM
Hello Jessie,
To prevent the user from entering more than 2 digits after the dedimal point you would have to validate your textbox. Check out the code that I implemented for the same scenario. You can alter the code according to your requirement:
c#:
js:
Thanks
Princy.
To prevent the user from entering more than 2 digits after the dedimal point you would have to validate your textbox. Check out the code that I implemented for the same scenario. You can alter the code according to your requirement:
c#:
| protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode ) |
| { |
| TextBox txtbx = (e.Item as GridEditableItem)["Value"].Controls[0] as TextBox; |
| txtbx.Attributes.Add("onKeyDown", "Validate(this)"); |
| } |
| } |
js:
| function Validate(ctrl) |
| { |
| var value=ctrl.value; |
| if(value!="") |
| { |
| var index=value.indexOf('.') |
| if(index!=-1) |
| { |
| var v=value.substring(index); |
| if(v.length>2) |
| { |
| alert("You cannot enter more than two digits after the decimal point"); |
| ctrl.maxLength=value.length; |
| } |
| } |
| } |
| } |
Thanks
Princy.
0
Jessie
Top achievements
Rank 1
answered on 10 Jun 2009, 01:35 PM
Thanks for all your help, Princy!