469,358 Members | 1,628 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

ObjectDataSource with Complex Objects and 2 way Databinding

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.

Nov 19 '05 #1
5 3265
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 Mo*****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
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.

Nov 19 '05 #2
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 19 '05 #3
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 Mo*****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
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.


Nov 19 '05 #4

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?


"as******@gmail.com" 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

Nov 19 '05 #5
i have exctly the same proble, but i culdn`t fix it with [Serializable()]. iŽll be very gracefullwith any help

From http://www.developmentnow.com/g/8_20...atabinding.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Jan 12 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by David Jessee | last post: by
reply views Thread by family | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.