473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

formating text in a textbox control?

djc
Is there a property or method of the textbox web server control that I can
use to format the text in it a certian way. For example I am displaying a
date value from a database in a text box. It displays like so: mm/dd/yyyy
mm:hh:ss. I 'was' using the .ToShortDateString() function like so:
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring() which
worked great until I came across a database record with NULL for this field.
It seems the best thing to do would be to have something attatched to the
textbox control itself that would control formating of it's own contents.
That way I would not need to add a NULL check before using the
..ToShortDateString() function.

any input would be appreciated. Thanks!
Nov 19 '05 #1
4 1555
Do a null check around it.

if(drMain.Item("EstimatedDeliveryDate") != null)
{
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring() ;
}
else
{
txtETA.Text = "";
}
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"djc" <no***@nowhere.com> wrote in message
news:Oj**************@TK2MSFTNGP15.phx.gbl...
Is there a property or method of the textbox web server control that I can
use to format the text in it a certian way. For example I am displaying a
date value from a database in a text box. It displays like so: mm/dd/yyyy
mm:hh:ss. I 'was' using the .ToShortDateString() function like so:
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring()
which
worked great until I came across a database record with NULL for this
field.
It seems the best thing to do would be to have something attatched to the
textbox control itself that would control formating of it's own contents.
That way I would not need to add a NULL check before using the
.ToShortDateString() function.

any input would be appreciated. Thanks!

Nov 19 '05 #2
I would highly recommend turning Option String On.

http://weblogs.asp.net/rchartier/arc.../13/58381.aspx

This would be a compile time error, and you would already have to handle it
differently.

Just like Curt said, you will have to do it in two steps.

if drMain.Item("EstimatedDeliveryDate") == DBNull.Value then
txtETA.Text = ""
else
txtETA.Text = CType( drMain.Item("EstimatedDeliveryDate" ),
DateTime).ToShortDateString()
end if

"djc" <no***@nowhere.com> wrote in message
news:Oj**************@TK2MSFTNGP15.phx.gbl...
Is there a property or method of the textbox web server control that I can
use to format the text in it a certian way. For example I am displaying a
date value from a database in a text box. It displays like so: mm/dd/yyyy
mm:hh:ss. I 'was' using the .ToShortDateString() function like so:
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring() which worked great until I came across a database record with NULL for this field. It seems the best thing to do would be to have something attatched to the
textbox control itself that would control formating of it's own contents.
That way I would not need to add a NULL check before using the
.ToShortDateString() function.

any input would be appreciated. Thanks!

Nov 19 '05 #3
djc
ok. Thank you.

"William F. Robertson, Jr." <theman_at_fdrsucks.com> wrote in message
news:uZ**************@TK2MSFTNGP14.phx.gbl...
I would highly recommend turning Option String On.

http://weblogs.asp.net/rchartier/arc.../13/58381.aspx

This would be a compile time error, and you would already have to handle it differently.

Just like Curt said, you will have to do it in two steps.

if drMain.Item("EstimatedDeliveryDate") == DBNull.Value then
txtETA.Text = ""
else
txtETA.Text = CType( drMain.Item("EstimatedDeliveryDate" ),
DateTime).ToShortDateString()
end if

"djc" <no***@nowhere.com> wrote in message
news:Oj**************@TK2MSFTNGP15.phx.gbl...
Is there a property or method of the textbox web server control that I can use to format the text in it a certian way. For example I am displaying a date value from a database in a text box. It displays like so: mm/dd/yyyy mm:hh:ss. I 'was' using the .ToShortDateString() function like so:
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring()

which
worked great until I came across a database record with NULL for this

field.
It seems the best thing to do would be to have something attatched to the textbox control itself that would control formating of it's own contents. That way I would not need to add a NULL check before using the
.ToShortDateString() function.

any input would be appreciated. Thanks!


Nov 19 '05 #4
djc
ok. Thank you.

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
Do a null check around it.

if(drMain.Item("EstimatedDeliveryDate") != null)
{
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring() ;
}
else
{
txtETA.Text = "";
}
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"djc" <no***@nowhere.com> wrote in message
news:Oj**************@TK2MSFTNGP15.phx.gbl...
Is there a property or method of the textbox web server control that I can use to format the text in it a certian way. For example I am displaying a date value from a database in a text box. It displays like so: mm/dd/yyyy mm:hh:ss. I 'was' using the .ToShortDateString() function like so:
txtETA.Text = drMain.Item("EstimatedDeliveryDate").ToShortDateSt ring()
which
worked great until I came across a database record with NULL for this
field.
It seems the best thing to do would be to have something attatched to the textbox control itself that would control formating of it's own contents. That way I would not need to add a NULL check before using the
.ToShortDateString() function.

any input would be appreciated. Thanks!


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom | last post by:
Is there any way to use conditional formating to change a control for a field in a continuous form to a textbox, option group or combobox depending on the value of another field on the form? On a...
0
by: Dmitri Manushin | last post by:
Hi all, i have textBox (multiline) i'am enter many words and don't push enter next i push button and text record in database. When i read data from database in table i'am use teg <pre> for save...
1
by: Hardik Shah | last post by:
Hi, I want to use various formating on text box , like text box gets only neumeric value, or text box can get only no of character. etc. Any hints will be sincerely appreciated. Hardik...
11
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in...
3
by: dmbuso | last post by:
I have a money field defined in a SQL Server 05 database with a value of 49.50. Also, it displays in SQL Server as 49.5000. I have a form in VB.NET 2005 and I'm using the new MaskedTextBox control...
0
by: andytsummers | last post by:
Hi I have tried to implement drag and drop by using the following code but I have several problems. 1. When you put your mouse over selected text the cursor is still the i-beam and therefore...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
11
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I know I sound like a one-note Johnny on this but I'm still looking for a solution. I need to display characters coming in from a serial port or a socket. I also need to be able to type...
4
by: randy.buchholz | last post by:
I am looking for a way to apply a format by data type. For example, I would like to format all dates as {0:d} without having to do each by hand. I am using themes and looked around there but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.