473,625 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding Dates in ASP .Net 2.0

Is there a good way to databind a textbox to a date field that will not throw
an error when a null is encountered. I tried changing the Null Value in the
dataset , but when I do I get the following message:

For columns not defined as System.String, the only valid value is (Throw
exception).

Normally when a date is not set, I leave it null. Even if I used a value to
represent not set (1/1/1900), I wouldn't want this to display on the form.
This wouldn't be an issue in 1.1, since I could just bind to a method passing
the field, and access the dataset in the code behind. In 2.0, you have to
use the objectdatasourc e control, and I do not have access to the underlying
dataset.

If anyone has any ideas, I would appreciate it.
Nov 19 '05 #1
7 1363
You can pass a SqlDateTime, instead of a DateTime, to hold a Null value.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Is there a good way to databind a textbox to a date field that will
not throw an error when a null is encountered. I tried changing the
Null Value in the dataset , but when I do I get the following message:

For columns not defined as System.String, the only valid value is
(Throw exception).

Normally when a date is not set, I leave it null. Even if I used a
value to represent not set (1/1/1900), I wouldn't want this to display
on the form. This wouldn't be an issue in 1.1, since I could just
bind to a method passing the field, and access the dataset in the code
behind. In 2.0, you have to use the objectdatasourc e control, and I
do not have access to the underlying dataset.

If anyone has any ideas, I would appreciate it.


Nov 19 '05 #2
So since the SqlDateTime is not supported in a dataset, you basically can't
do this if your objectdatasourc e is using a dataset. Is that correct?

"Brock Allen" wrote:
You can pass a SqlDateTime, instead of a DateTime, to hold a Null value.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Is there a good way to databind a textbox to a date field that will
not throw an error when a null is encountered. I tried changing the
Null Value in the dataset , but when I do I get the following message:

For columns not defined as System.String, the only valid value is
(Throw exception).

Normally when a date is not set, I leave it null. Even if I used a
value to represent not set (1/1/1900), I wouldn't want this to display
on the form. This wouldn't be an issue in 1.1, since I could just
bind to a method passing the field, and access the dataset in the code
behind. In 2.0, you have to use the objectdatasourc e control, and I
do not have access to the underlying dataset.

If anyone has any ideas, I would appreciate it.


Nov 19 '05 #3
> So since the SqlDateTime is not supported in a dataset, you basically
can't do this if your objectdatasourc e is using a dataset. Is that
correct?


Why do you say that? It works fine for me. It probabaly doesn't display exactly
how you'd like when it's null, since that's exactly what it does display:
"Null". The other idea it to either create your own class to hold the DateTime
and override ToString() returning the empoty string when null, or handle
the GridView's (or DataGrid's) RowDataBound (or ItemDataBound) and then going
into the cell that has the null value and changing it to contain an empty
string when the DateTime is null.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #4
>> So since the SqlDateTime is not supported in a dataset, you basically
can't do this if your objectdatasourc e is using a dataset. Is that
correct?

Why do you say that? It works fine for me.


Oops, I completely misread that you had said DataSet. I read it as DataGrid.
In that case from your ObjectDataSourc e instead of returning DataSets, consider
returning a collection of custom classes. Sorry for the confusion.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #5
Okay, so instead of ASP.Net reducing the amount of time required for me to
develop this page, it is increasing it by 4 - 6 hours while I develop this
class that will basically wrap the dataset.

This is also forcing me to move the formating of my dates from the ui (where
it belongs) to the business class.

"Brock Allen" wrote:
So since the SqlDateTime is not supported in a dataset, you basically
can't do this if your objectdatasourc e is using a dataset. Is that
correct?

Why do you say that? It works fine for me.


Oops, I completely misread that you had said DataSet. I read it as DataGrid.
In that case from your ObjectDataSourc e instead of returning DataSets, consider
returning a collection of custom classes. Sorry for the confusion.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #6
Well, like I said before as another idea would be to handle the Item/RowDataBound
event and do all your formatting in the page.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Okay, so instead of ASP.Net reducing the amount of time required for
me to develop this page, it is increasing it by 4 - 6 hours while I
develop this class that will basically wrap the dataset.

This is also forcing me to move the formating of my dates from the ui
(where it belongs) to the business class.

"Brock Allen" wrote:
So since the SqlDateTime is not supported in a dataset, you
basically can't do this if your objectdatasourc e is using a
dataset. Is that correct?

Why do you say that? It works fine for me.

Oops, I completely misread that you had said DataSet. I read it as
DataGrid. In that case from your ObjectDataSourc e instead of
returning DataSets, consider returning a collection of custom
classes. Sorry for the confusion.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #7
There is no such event in the formview, but there is a databound and
databinding event. The problem is that there is no way to access the
ObjectDataSourc e underlying data object to retrieve the data. I can
implement a custom binding method, but without access to the underlying data
it is useless.

Actually I just figured it out. Apparently, you can access the current data
item through the formview instead of the objectdatasourc e. Using this
information, I can properly bind the date. Now all I have to do is figure
out how to make this work with two way binding.

"Brock Allen" wrote:
Well, like I said before as another idea would be to handle the Item/RowDataBound
event and do all your formatting in the page.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Okay, so instead of ASP.Net reducing the amount of time required for
me to develop this page, it is increasing it by 4 - 6 hours while I
develop this class that will basically wrap the dataset.

This is also forcing me to move the formating of my dates from the ui
(where it belongs) to the business class.

"Brock Allen" wrote:
> So since the SqlDateTime is not supported in a dataset, you
> basically can't do this if your objectdatasourc e is using a
> dataset. Is that correct?
>
Why do you say that? It works fine for me.

Oops, I completely misread that you had said DataSet. I read it as
DataGrid. In that case from your ObjectDataSourc e instead of
returning DataSets, consider returning a collection of custom
classes. Sorry for the confusion.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #8

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

Similar topics

1
1345
by: GMG | last post by:
By providing a DTD in an XML document which is bound to HTML controls, Internet Explorer will automatically format the display of the date fields. For example 2004-08-03T00:00:00 will be displayed as 08/03/2004. It is a fantastic feature, but how does it determine which format to display it in ? The format that is being displayed on the samples I am looking at does not match my regional settings. All the dates are displayed in US format...
3
1716
by: funkyMonkey | last post by:
I'm binding date fields from entity objects and formatting the output in the text box in short date format. Code: BindDateField(Me.txtCheckIn, "Text", reservation.BookingDetail, "CheckIn") BindDateField(Me.txtCustTravleDate, "Text", reservation.BookingDetail, "CheckIn") BindDateField(Me.txtCheckOut, "Text", reservation.BookingDetail, "CheckOut")
8
2174
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
3
8684
by: John | last post by:
I'm getting this error when i'm trying to databind my dataset to a dropdown: DataBinding: 'System.Data.DataRowView' does not contain a property with the name '12/12/2003' but if I do a response.write I can see the dates fine, what is causing this error? code: dYear.DataSource = dsYearofSales.Tables; string strYearofSales = dsYearofSales.Rows.tostring(); dYear.DataTextField =
0
8182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.