Databinding in ASP.NET 2.0

Databinding in ASP.NET 2.0

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


Walt posted on Sunday, November 18, 2007

I have been using CSLA 1.5 for several years in a Windows forms app, and am now trying to code an ASP.NET app using the same class library (LynxLibrary) for business objects.  One of my business objects (Tnail) inherits from BusinessBase and contains a child object (SFList) inheriting from ReadOnlyCollectionBase.  I am using an ObjectDataSource to bind several GridView controls on a page to the Tnail object with a Public Shared Function GetTnail() in the Tnail business object.  The child object (SFList) has a Public Structure with 3 Public properties (Label, Data, and Required).

When I run, I get an error on the page "DataBinding:  LynxLibrary.SFList does not contain a property with the name 'Label'".  This occurs with the first property I try to get.  I use <%# Eval (SearchFields.Label %> to bind the data in the GridView.  SearchFields is the public property in Tnail that returns the SFList child object.  I do get all of the properties on the BusinessBase class (Tnail).  I thought the purpose of creating private members and public properties in the public structure of a ReadOnlyCollectionBase was to allow ASP.NET data binding.

Incidentally, if I create a tnail object in code (rather than through the ObjectDataSource), I can see all properties in the parent and child objects.

Any help would be very much appreciated.

DavidDilworth replied on Wednesday, November 21, 2007

To do the data binding I think you are suggesting in ASP.NET you need to use a CslaDataSource instead of an ObjectDataSource.

Have you tried that?

Walt replied on Thursday, November 22, 2007

Thanks David,

I haven't tried a CslaDataSource.  I will look that up and see how to implement it.  Until now I have been using CSLA 1.x, and haven't come accross CslaDataSource.  I have tried binding to a business object that inherits BusinessBase, but that didn't work.  This is my first venture in ASP.NET, so I'm sure I'm missing something important.

JoeFallon1 replied on Sunday, November 25, 2007

The ObjectDataSource has some very strict requirements which are NOT friendly to CSLA.

I believe the Public Sub New is the biggest issue.

The CslaDataSource obviously takes these things into account and is better for handling these issues.

That said, I do not use it. I have not found a need to do so yet. I do have 2-way binding controls though. I use some code provided by Rick Strahl.

Joe

 

Copyright (c) Marimer LLC