String format

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

In my aspx-app I do the following

this.TextBox1.text ="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 ( == 0)
   this.TextBox1.text = "";
   this.TextBox1.text =;

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.

( == 0) ? TextBox1.Text="" : TextBox1.Text =;

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
XML & .net 5 40
Page navigation in windows phone 8.1 application not working. 5 17
Exit the loop 4 34
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

911 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

19 Experts available now in Live!

Get 1:1 Help Now