Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

String format

Posted on 2004-10-19
2
Medium Priority
?
248 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
[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 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 150 total points
ID: 12377104
Did this address your need? There is no other way of doing what you are thinking of
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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!
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

661 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