2-Way Databinding without the DataSources from 2.0

G

Guest

L.S.,

Hello is there a way to implement 2-way databinding without using the
datasources from dotnet 2.0. Why would you ask? Now that's simple.

I've created an object model with BusinessObjects and I don't want to write
an separate provider layer for the datasources. This is because I loose all
the benefits of my objectmodel.

Are there other developers who think this way?

Thanx in advance.

Greetz,
 
G

Guest

When I was programming in ASP.NET 1.1, I implemented 2-way data binding using
my own custom data bound tem plated control (or creating a composite control
out of the repeater). This allowed me to use templates against a BLL. In
ASP.NET 2.0 I found, so far, the objectdatasource to be a very helpful for
RAD. I think it is a great improvement.
 
G

Guest

Yeah I did something like that in asp.net 1.1. But I'm not happy with the
design
of Microsoft about the ObjectDataSource, because if you use an genuine
objectmodel u can't use the ObjectDataSource for Updating/Deleting/Inserting
you can only use Select.

If you realy want to use the objectdatasource you'lle have to write an
CRUD-layer who is very close of the UI (in my meaning design fault),
this layer must implement some CRUD methods. These CRUD-methods can use your
normal businesslayer.

I had hoped Microsoft created an independent layer for binding
objects/datasets to controls (ASP.NET or WinForms), now I will have to write
all those things myself.

By the way I'm interested in your "own custom data bound tem plated control
", because my own controls where not 2 way.

Greetz,
 
G

Guest

Hi Joey,

I am not sure why you say that you “can't use the ObjectDataSource for
Updating/Deleting/Inserting†and that “you can only use Select.†The demos
on my website www.webswapp.com update the records using an objectDataSource
that updates the data through a BLL. You can use a BLL class by specifying a
value for the DataObjectTypeName.

For example in this demo
http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c.aspx I pass to the
update method a customized class and defines parameters that the
objectDataSource would set within that class.

As for my custom dataBound Templated Control that I referred to in the
previous message, if you are interested in creating one you might:

1- read this article for Scott Mitchell on creating databound templated
controls:
http://msdn.microsoft.com/library/d...us/dnaspp/html/databoundtemplatedcontrols.asp

2- Create your own templates (as the sample in step 1 demonstrated)

3- For controls, such as textboxes, that are not databound by default, add a
step that is not in Scott’s demo where you create your own custom controls of
the existing server controls:
a. Persist the content in the ViewState upon setting a property of
the control
b. Handle the MyBase.DataBinding event to bind the content to the
control then
c. Handle other events upon change of data inside the server
control, for example,
i. MyBase.TextChanged event for the TextBox server control:
during this step you would call a method that would update the data within
the class associated with this control
 
G

Guest

Phillip,

First of all thanks for your anwser. When I create business-objectmodel I
make something like this:

public class Address
{
public Address(int id) { Dal.Get() }

public bool Delete() { Dal.Delete() }

public bool Save() { Dal.Save() }

public static GetAllAddresses() { Dal.GetAllAddresses() }

private int _id = int.MinValue;
public int Id { get { return _id } }

...some other properties and methods...
}

If you do it like this way, and this is a normal businessobjectmodel,
you can't use this class in the ObjectDataSource, you'll have to write
an descendant or create an provider who gets ands sets businessobjects
for u. Something like:

public class AddressProvider
{
public static bool Update(int id, string city, etc)
{
Address a = new Address(id);
a.City = city;
return a.Save();
}

... etc .....
}

I'm convinced that this isn't the right way to do it, but if it can't be done
I will have to work with it.

I hope you understand me now ;-)

Greetz,

Joey Chömpff
 
G

Guest

Hi Joey,

Actually, your class would work just fine if you were to make one simple
modification: namely a default constructor. Note that you need “setâ€
statements for the properties whose values are to be updated by parameters
collection of the objectDatasource. For example your class can look like
this:

public class Address
{

public Address(){
//this default constructor is essential for the
objectdatasource //
}

// the rest of your class as is; only make sure you have set statements
// for the properties that the ObjectDataSource would pass from the
// UpdateParameters collection
}

You can look at the demos on my website for a proof of this concept.
 
G

Guest

Phillip,

I can live with an default constructor, but how do you handle
readonly fields like Id's, etc. These fields are set by the dal or
the businessobject itself and cannot be modified from outside.

Could u give me an working example of your BusinessLayer?

Greetz,

Joey Chömpff
 
G

Guest

Ok… I see what you mean… you are right… in your scenario; you will have to
write a descendant class or a provider to be able to utilize your classes in
the ObjectDataSource server control.
 
G

Guest

Phillip,

Thanx for thinking with me,

I've have an solution but it isn't a perfect one.
I have made partial classes of my businessobjects and newed the properties
who are readonly. Then i made an Update, Delete and Insert methods on the
partial classes who accepts a parameter of the partial class.

I hope that MS creates an independent layer for databinding in the near
future.

Greetz,

Joey Chömpff
 

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,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top