Solved

String format

Posted on 2004-10-19
2
211 Views
Last Modified: 2010-04-15
Hey,

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 = "";
else
   this.TextBox1.text = object.property.tostring();







Thanks
nic
0
Comment
Question by:haezeban
  • 2
2 Comments
 
LVL 3

Expert Comment

by:aacool
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.

e.g
Use
SetTxt(TextBox1,object.property);

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

Accepted Solution

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

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 (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. 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