Solved

format date in text box control

Posted on 2003-11-17
5
1,101 Views
Last Modified: 2012-05-04
I have a form with an underlying dataset (from a sql server db) that is bound to various textboxes.  A couple of the fields in the dataset contain dates.  Is there a way to format the dates in the text boxes.

Currently they display as ‘06/10/2003 00:00:00’

I need them to display as 06/10/2003.

Is this possible?
0
Comment
Question by:WingYip
5 Comments
 
LVL 1

Expert Comment

by:ob2
ID: 9763177
Easy Peasy

1) TextBox.Text = String.Format("{0:d}", Date)

Where d is always lowercase for short date and where date is the date from your dataset.
0
 
LVL 3

Accepted Solution

by:
the-edge earned 50 total points
ID: 9763226
use the Binding.Format Event

search "Binding.Format Event" in msdn for further details

from msdn:
Remarks
The Format event occurs both when data is pushed from the data source into the control, and when the data is pulled from the control into the data source. When the data is pushed from the data source into the control, the Binding will use the Format event to put the formatted data into the control. When the data is pushed from the control into the data source, the Binding will first parse the data using the Parse event, then format the data and push the it into the control.

The Format and Parse events allow you to create custom formats for displaying data. For example, if the data in a table is of type Decimal, you can display the data in the local currency format by setting the Value property of the ConvertEventArgs object to the formatted value in the Format event. You must consequently unformat the displayed value in the Parse event.

The Format event occurs whenever the Current value of the BindingManagerBase changes, which includes:

The first time the property is bound.
Any time the Position changes.
Whenever the data-bound list is sorted or filtered, which is accomplished when a DataView supplies the list.
The Format event also occurs after the Parse event. For example, when a control loses focus, its contents are parsed. Immediately afterwards, as new data is pushed into the control, the Format event occurs allowing the new contents to be formatted.



the edge
0
 
LVL 3

Expert Comment

by:the-edge
ID: 9763248
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10268075
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: ob2 {http:#9763177} & the-edge {http:#9763248}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 
LVL 1

Author Comment

by:WingYip
ID: 10280269
Have just tested the code.

the-edge gets the points

Thanks

Wing
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

12 Experts available now in Live!

Get 1:1 Help Now