Two-way databinding to Business Object (ASP.NET 2.0)

G

Guest

Is there any way to do this without using the ObjectDataSource? (Apologies
for the long post)

I have a simple data object:
public class TestDO
{
public TestDO() {}
public ID { get; set; }
public Name { get; set; }
public Description { get; set; }
}

Under .NET 1.1 I could bind directly to this object for one-way databinding,
although I built in support using custom controls for two-way databinding.

Now, I seem to have to use the ObjectDataSource which means I create a class
like follows:

public class ORDataObjectBinder
{
public DataObject Select()
{
returns new object;
}

public DataObject Select(string sId)
{
returns object by custom OR/mapper;
}

public void Update(DataObject doUpdated)
{
update data object using custom OR/mapper;
}
}

I then create a FormView in a page with bound controls for Name and
Description, create an ObjectDataSource as follows:
_odsProfile = new ObjectDataSource();
_odsProfile.TypeName = "ORDataObjectBinder";
_odsProfile.SelectMethod = "Select";
_odsProfile.UpdateMethod = "Update";
_odsProfile.ID = "GridProfileSource";
this.Controls.Add(_odsProfile);

Now, I can load the FormView up just fine, but when I click the Save button,
which fires off the Update method I get this error:

ObjectDataSource 'GridProfileSource' could not find a non-generic method
'Update' that has parameters: Name, Description.

Which says I need an Update(Name, Description) method on my
ORDataObjectBinder. If I only have Name bound control in the Formview it
wants an Update(Name) method.

However, I DO NOT WANT TO DO THIS! This would be a maintanence nightmare as
if I have to have an update method, with all the parameter permutations, for
every object in my system... geesh, thats not very handy at all.

Does anyone know how I can get the system to just use the Update(DataObject)
method instead?
 
G

Guest

In regards to your last question, you should be able to just have a function

Public void Update(TestDo x)

Since u didn't include all your code make sure your class is structured with
private field/public property. It might also have to have a new method.

I have used the objectdatasource update with passing it just the object
several times and it works great as long as it isn't a complex object.
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top