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

String format

Posted on 2004-10-19
Last Modified: 2010-04-15

In my aspx-app I do the following

this.TextBox1.text = object.property.tostring("N")

How can I force that when the value of the property (= Int32) = 0 that it is a space and not 0 in my textbox. I will have an empty textbox.:

Now I do (and I think there is something shorter)

if (object.property == 0)
   this.TextBox1.text = "";
   this.TextBox1.text = object.property.tostring();

Question by:haezeban
  • 2

Expert Comment

ID: 12347216
Well, you can use the ternary operator - this is one-line. It does not save much in the current case.

(object.property == 0) ? TextBox1.Text="" : TextBox1.Text = object.property.ToString();

If you have this kind of check in many places, perhaps you can put in a function with the code above and call it wherever needed.


Calls this function
private void SetTxt(System.Windows.Forms.TextBox TextBox1,object prop)
   (prop == 0) ? TextBox1.Text="" : TextBox1.Text = prop.ToString();

Accepted Solution

aacool earned 50 total points
ID: 12377104
Did this address your need? There is no other way of doing what you are thinking of

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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