ObjectDataSource with Complex Objects and 2 way Databinding

G

Guest

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

Bruce Barker

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)
 
A

as.davey

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
 
G

Guest

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
 
G

Guest

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top