binding to a child collection property of a CSLA object in ASP.NET

binding to a child collection property of a CSLA object in ASP.NET

Old forum URL: forums.lhotka.net/forums/t/9244.aspx


pkouzov posted on Wednesday, July 21, 2010

I am looking for the "correct" way to handle this as opposed to a workaround in the ASP.NET code behind. Here is the scenario:

I have a CSLA object which has a child collection as a property (e.g. think of a customer object with property phonenumbers, which is a collection). How on an ASP.NET page can I bind a gridview to the child collection of phonenumbers? I tried binding to a CslaDataSource, however seems like I can only bind the CslaDataSource to the main customer object, not the phonenumbers collection.

Jav replied on Wednesday, July 21, 2010

"CslaDataSource" suggests that you are likely using Csla v2.x

In that case you create SelectObject, InsertObject, UpdateObject and DeleteObject EventHandlers for you CslaDataSource.  For example, if your CslaDataSource is named PhoneDataSource, you will have the following event handler for the SelectObject event:

Protected Sub PhoneDataSource_SelectObject(ByVal sender As Object, ByVal e As Csla.Web.SelectObjectArgs)
 Handles PhoneDataSource.SelectObject
            e.BusinessObject = Customer.PhoneCollection
 End Sub

Now when you set the gridview's DataSource to PhoneDataSource, the gridview will display the phone numbers.  Similarly you will need to create the event handlers for the other three events so that you can send the inserts and updates to the database.

Jav

Copyright (c) Marimer LLC