473,414 Members | 1,744 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,414 software developers and data experts.

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 objectdatasource 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 1353
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 objectdatasource 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 objectdatasource 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 objectdatasource 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 objectdatasource 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 objectdatasource 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 ObjectDataSource 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 objectdatasource 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 ObjectDataSource 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 objectdatasource 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 ObjectDataSource 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
ObjectDataSource 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 objectdatasource. 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 objectdatasource 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 ObjectDataSource 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
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...
3
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")...
8
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...
3
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.