ObjectDataSource with Complex Objects and 2 way Databinding

Discussion in 'ASP .Net' started by =?Utf-8?B?VHJhaWwgTW9uc3Rlcg==?=, Nov 3, 2005.

  1. Ok, I've been searching the net now for several days and can't find how to do
    this anywhere.

    Version:
    VS 2005 Professional Release, 2.0 Framework

    Background:
    I have a complex business object Employee that contains public properties
    and several nested objects such as a Spouse object and a List of Coverage
    objects.
    All data access goes through a DAL

    I'm currently able to use an objectdatasource to populate a gridview control
    with employee information, displaying the "base" employee information binds
    and works like normal, however inorder to display data from one of the nested
    objects it gets a little tricky. Currently I am using a template column and
    custom databinding expression such as

    DirectCast(Container.DataItem, Employee).Spouse.Name

    Problem 1:
    This works for displaying the data but does not facilate updating. The
    binding is only 1 way, i can't figure out how to use the 2 way Bind("asdlfj")
    expression to work with a complex object.

    Problem 2:
    When the objectdatasource then calls the update Function it passes an
    Employee object as the parameter. The passed in employee object's base
    properties are fine, however all the nested object properties are set to
    Nothing, I was able to fix this by changing the class declacration from
    Public Class Spouse to

    <Serializable()> Public Class Spouse



    I am not real familiar with Serialization and what other effects this has on
    my class though. An explanation of what this is doing and if it is the
    correct way of doing this would be appreciated.


    Letting off steam:
    I can't believe that Microsoft would promote the objdatasource as much as it
    seems they are if it can't easily handle complex object structures. If the
    application is complex enough to justify a 3+ tier design then chances are
    the objects are gonna be complex. . . . . If 2 way data binding isnt'
    possible with complex objects then the objectdatasource is a complete waste.
    Hopefully i'm wrong and this all works, in which case it will be VERY nice.

    Thanks for your help in advance.
    =?Utf-8?B?VHJhaWwgTW9uc3Rlcg==?=, Nov 3, 2005
    #1
    1. Advertising

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

    Bruce Barker Guest

    you are supposed to supply objectdatasource with interfaces to you BI
    object that it can use. it wants enum collections that it can update, and
    methods to call on select/update/delete and modify updates to these
    collections.

    -- bruce (sqlwork.com)



    "Trail Monster" <Trail > wrote in message
    news:...
    > Ok, I've been searching the net now for several days and can't find how to
    > do
    > this anywhere.
    >
    > Version:
    > VS 2005 Professional Release, 2.0 Framework
    >
    > Background:
    > I have a complex business object Employee that contains public properties
    > and several nested objects such as a Spouse object and a List of Coverage
    > objects.
    > All data access goes through a DAL
    >
    > I'm currently able to use an objectdatasource to populate a gridview
    > control
    > with employee information, displaying the "base" employee information
    > binds
    > and works like normal, however inorder to display data from one of the
    > nested
    > objects it gets a little tricky. Currently I am using a template column
    > and
    > custom databinding expression such as
    >
    > DirectCast(Container.DataItem, Employee).Spouse.Name
    >
    > Problem 1:
    > This works for displaying the data but does not facilate updating. The
    > binding is only 1 way, i can't figure out how to use the 2 way
    > Bind("asdlfj")
    > expression to work with a complex object.
    >
    > Problem 2:
    > When the objectdatasource then calls the update Function it passes an
    > Employee object as the parameter. The passed in employee object's base
    > properties are fine, however all the nested object properties are set to
    > Nothing, I was able to fix this by changing the class declacration from
    > Public Class Spouse to
    >
    > <Serializable()> Public Class Spouse
    >
    >
    >
    > I am not real familiar with Serialization and what other effects this has
    > on
    > my class though. An explanation of what this is doing and if it is the
    > correct way of doing this would be appreciated.
    >
    >
    > Letting off steam:
    > I can't believe that Microsoft would promote the objdatasource as much as
    > it
    > seems they are if it can't easily handle complex object structures. If
    > the
    > application is complex enough to justify a 3+ tier design then chances are
    > the objects are gonna be complex. . . . . If 2 way data binding isnt'
    > possible with complex objects then the objectdatasource is a complete
    > waste.
    > Hopefully i'm wrong and this all works, in which case it will be VERY
    > nice.
    >
    > Thanks for your help in advance.
    >
    Bruce Barker, Nov 3, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?VHJhaWwgTW9uc3Rlcg==?=

    Guest

    Yeah....

    I'm having a similar problem. I've not been able to find anywhere more
    details on the Bind syntax in relation to nested business objects
    (don't even get me started on whats involved in getting business
    objects with Collections as properties to one way bind ~ let alone two
    way binding).

    Re your second problem, I eventually decided to go with static helper
    classes within my App_Code folder. Essentially these classes are
    designed to be used solely by the ObjectDataSource and have those
    lovely 100 parameter long (I'm exagerating a little) static methods for
    populating the Business Object. As opposed to creating BO's that have
    public default constructors etc etc

    I think MS documentation could be a little clearer on what you can and
    can't acheive with the ObjectDataSource. And maybe rename the control
    to the SimpleObjectDataSource :p

    Hope this helps,

    Andy
    http://workingandy.blogspot.com
    , Nov 4, 2005
    #3
  4. Bruce,

    I have already set the select and update functions in the objectdatasource.
    They are getting called correctly it just isn't doing the 2 way databinding
    on nested object properties. Everything works great on a with a simple flat
    object. . .


    "Bruce Barker" wrote:

    > you are supposed to supply objectdatasource with interfaces to you BI
    > object that it can use. it wants enum collections that it can update, and
    > methods to call on select/update/delete and modify updates to these
    > collections.
    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    > "Trail Monster" <Trail > wrote in message
    > news:...
    > > Ok, I've been searching the net now for several days and can't find how to
    > > do
    > > this anywhere.
    > >
    > > Version:
    > > VS 2005 Professional Release, 2.0 Framework
    > >
    > > Background:
    > > I have a complex business object Employee that contains public properties
    > > and several nested objects such as a Spouse object and a List of Coverage
    > > objects.
    > > All data access goes through a DAL
    > >
    > > I'm currently able to use an objectdatasource to populate a gridview
    > > control
    > > with employee information, displaying the "base" employee information
    > > binds
    > > and works like normal, however inorder to display data from one of the
    > > nested
    > > objects it gets a little tricky. Currently I am using a template column
    > > and
    > > custom databinding expression such as
    > >
    > > DirectCast(Container.DataItem, Employee).Spouse.Name
    > >
    > > Problem 1:
    > > This works for displaying the data but does not facilate updating. The
    > > binding is only 1 way, i can't figure out how to use the 2 way
    > > Bind("asdlfj")
    > > expression to work with a complex object.
    > >
    > > Problem 2:
    > > When the objectdatasource then calls the update Function it passes an
    > > Employee object as the parameter. The passed in employee object's base
    > > properties are fine, however all the nested object properties are set to
    > > Nothing, I was able to fix this by changing the class declacration from
    > > Public Class Spouse to
    > >
    > > <Serializable()> Public Class Spouse
    > >
    > >
    > >
    > > I am not real familiar with Serialization and what other effects this has
    > > on
    > > my class though. An explanation of what this is doing and if it is the
    > > correct way of doing this would be appreciated.
    > >
    > >
    > > Letting off steam:
    > > I can't believe that Microsoft would promote the objdatasource as much as
    > > it
    > > seems they are if it can't easily handle complex object structures. If
    > > the
    > > application is complex enough to justify a 3+ tier design then chances are
    > > the objects are gonna be complex. . . . . If 2 way data binding isnt'
    > > possible with complex objects then the objectdatasource is a complete
    > > waste.
    > > Hopefully i'm wrong and this all works, in which case it will be VERY
    > > nice.
    > >
    > > Thanks for your help in advance.
    > >

    >
    >
    >
    =?Utf-8?B?VHJhaWwgTW9uc3Rlcg==?=, Nov 4, 2005
    #4
  5. My employee object contains

    Public Property Coverages() As List(Of Coverage)
    Get
    Return _Coverages
    End Get
    Set(ByVal value As List(Of Coverage))
    _Coverages = value
    End Set
    End Property

    I am able to use the following syntax to 1 way Bind to the Coverage
    properties in the collection

    DirectCast(Container.Dataitem, Employee).Coverages(integer index).Name

    However what i need to be able to do is put nest a gridview in a template
    column and Bind the whole collection to the grid.

    Have u done anything like that?




    "" wrote:

    > Yeah....
    >
    > I'm having a similar problem. I've not been able to find anywhere more
    > details on the Bind syntax in relation to nested business objects
    > (don't even get me started on whats involved in getting business
    > objects with Collections as properties to one way bind ~ let alone two
    > way binding).
    >
    > Re your second problem, I eventually decided to go with static helper
    > classes within my App_Code folder. Essentially these classes are
    > designed to be used solely by the ObjectDataSource and have those
    > lovely 100 parameter long (I'm exagerating a little) static methods for
    > populating the Business Object. As opposed to creating BO's that have
    > public default constructors etc etc
    >
    > I think MS documentation could be a little clearer on what you can and
    > can't acheive with the ObjectDataSource. And maybe rename the control
    > to the SimpleObjectDataSource :p
    >
    > Hope this helps,
    >
    > Andy
    > http://workingandy.blogspot.com
    >
    >
    =?Utf-8?B?VHJhaWwgTW9uc3Rlcg==?=, Nov 4, 2005
    #5
  6. =?Utf-8?B?VHJhaWwgTW9uc3Rlcg==?=

    Esteban Guest

    Esteban, Jan 12, 2007
    #6
    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. Kevin
    Replies:
    0
    Views:
    691
    Kevin
    Aug 22, 2006
  2. jobs
    Replies:
    0
    Views:
    1,583
  3. Dan Caron
    Replies:
    1
    Views:
    169
  4. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    225
    Steven Cheng[MSFT]
    Mar 23, 2006
  5. Mythran
    Replies:
    3
    Views:
    1,212
    Allen Chen [MSFT]
    Aug 12, 2009
Loading...

Share This Page