Link to home
Start Free TrialLog in
Avatar of meetpd
meetpdFlag for India

asked on

How to implement thousand seperator for text-boxes in ASP.NET C# (500 pt)

Hi,

For textboxes having amount values, I need a thousand seperator.
Eg. If we enter amount as '15000', it should change it to '15,000'.

Also, because I have more than 50 such textboxes, I need a way to implement this in one shot.

Appreciate your help!
Avatar of Rahul Goel
Rahul Goel
Flag of India image

double value;

value = 1234567890;
Console.WriteLine(value.ToString("#,#", CultureInfo.InvariantCulture));    
// Displays 1,234,567,890      

Avatar of meetpd

ASKER

How can we apply this to all the textboxes?
two Solutions:

1> Implement a Ajax Mask Edit Extender (Out of the Box functionality) and attach it to ur text box ,a more professional approach as it will help u if tomorrow ur site switches for different language then ur Currency Format Will Change.

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx

2> A More easy approcah ,create a Custom Function to return a Number format

txtBox.text = ReturnFormat(NumToBeDisplayed);

string RetrunFormat(int Num)
{
  return Num.ToString("N");

}
txtBox.text = ReturnFormat(NumToBeDisplayed);
 
string RetrunFormat(int Num)
{
  return Num.ToString("N");
 
} 

Open in new window

Avatar of meetpd

ASKER

Hi DreamsTech,

I tried the solution that you gave. But it inserts two 0s after decimal.(e.g. 13,000.00) How can I remove those so that I get (e.g. 13,000) ?

Thanks!

Avatar of meetpd

ASKER

Also, I would want this to happen when the cursor is out of the textbox. How to do that?
ASKER CERTIFIED SOLUTION
Avatar of Jalaly
Jalaly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial