Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Databinding Dates in ASP .Net 2.0

Reply
Thread Tools

Databinding Dates in ASP .Net 2.0

 
 
=?Utf-8?B?Sm9obiBCYWlsZXk=?=
Guest
Posts: n/a
 
      06-12-2005
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.
 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      06-12-2005
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.
>




 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCYWlsZXk=?=
Guest
Posts: n/a
 
      06-12-2005
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.
> >

>
>
>
>

 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      06-12-2005
> 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




 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      06-12-2005
>> 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



 
Reply With Quote
 
=?Utf-8?B?Sm9obiBCYWlsZXk=?=
Guest
Posts: n/a
 
      06-12-2005
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
>
>
>
>

 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      06-12-2005
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




 
Reply With Quote
 
=?Utf-8?B?Sm9obiBCYWlsZXk=?=
Guest
Posts: n/a
 
      06-13-2005
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

>
>
>
>

 
Reply With Quote
 
elizas elizas is offline
Junior Member
Join Date: Jan 2010
Location: India
Posts: 29
 
      04-28-2010
ObjectDataSource Control has five mostly used properties:
1.TypeName :the name of the type of object the control representing
2.SelectMethod :the method name the ObjectDataSource calls for selecting data
3.UpdateMethod :the method name the ObjectDataSource calls for updating data
4.InsertMethod :the method name the ObjectDataSource calls for inserting data
5.DeleteMethod :the method name the ObjectDataSource calls for deleting data
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RFC-822 dates into Ruby dates kellygreer1 Ruby 1 06-08-2008 10:59 PM
Need to use dates earlier than 1900 (Time library says out of range for dates < 1900) me@benjaminarai.com Ruby 1 07-17-2007 02:25 PM
FAQ Dates; Opera Dates. Dr J R Stockton Javascript 0 06-18-2007 03:51 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments