Solved

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

Posted on 2008-06-20
5
496 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
Comment Utility
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
Comment Utility
Hi NeoTeq,

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

Accepted Solution

by:
prairiedog earned 125 total points
Comment Utility
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
Comment Utility
If you got your answer, will you please close the question?
0
 

Author Comment

by:feesu
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now