Databinding Dates in ASP .Net 2.0

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 12, 2005.

  1. 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.
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 12, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Brock Allen Guest

    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.
    >
    Brock Allen, Jun 12, 2005
    #2
    1. Advertising

  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?

    "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.
    > >

    >
    >
    >
    >
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 12, 2005
    #3
  4. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Brock Allen Guest

    > 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
    Brock Allen, Jun 12, 2005
    #4
  5. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Brock Allen Guest

    >> 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
    Brock Allen, Jun 12, 2005
    #5
  6. 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
    >
    >
    >
    >
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 12, 2005
    #6
  7. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Brock Allen Guest

    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
    Brock Allen, Jun 12, 2005
    #7
  8. 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

    >
    >
    >
    >
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jun 13, 2005
    #8
  9. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    elizas

    Joined:
    Jan 27, 2010
    Messages:
    27
    Location:
    India
    Binding ObjectDataSourceControl to a collection in ASP.Net 3.5

    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
    elizas, Apr 28, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    859
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    192
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    205
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    195
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    159
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page