Solved

ASP.NET 2005 - String.Format doesn't affect a text box!

Posted on 2008-06-20
5
514 Views
Last Modified: 2013-11-26
Hi,

I am trying to format some numbers in my text box by using:

Me.Subscribed_QTY.Text = Format(Me.Subscribed_QTY.Text.ToString, "{0:##,#}")

However, if the value of the text box is 1000 it doesn't change! What should I do?

0
Comment
Question by:feesu
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:NeoTeq
ID: 21833537
You will need to convert it to a number before it can format it as one.
Me.Subscribed_QTY.Text = CType(Me.Subscribed_QTY.Text, Decimal).ToString("{0:##,#}")

Open in new window

0
 

Author Comment

by:feesu
ID: 21835748
Hi NeoTeq,

I tried what you sent me. It doesn't work.
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 125 total points
ID: 21847739
If the value of the text box is always Integer, then you can try:
Me.Subscribed_QTY.Text = String.Format("{0:##,#}", Int32.Parse(Me.Subscribed_QTY.Text))
If the value of the text box is always Decimal, then you can try:
Me.Subscribed_QTY.Text = String.Format("{0:##,#}", Decimal.Parse(Me.Subscribed_QTY.Text))

The second one will also work for Integer values.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21885207
If you got your answer, will you please close the question?
0
 

Author Comment

by:feesu
ID: 21895827
prairiedog,

I have tested this code, and observed the following:

1- The formatted number inside the text box cannot be used in calculations; 60,000 is read as 60 !

2- I needed to format the text box even if it's empty but  I am getting an error. How can I do that?

Currently I call this:
 Me.Subscribed_QTY.Text = String.Format("{0:##,#}", Decimal.Parse(Val(Me.Subscribed_QTY.Text)))



Thanks for helping me cuz I'm new to this.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question