Solved

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

Posted on 2008-06-20
5
533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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