views:

28

answers:

0

Howdy,

Recently I returned to ASP.NET WebForms programming and I've come across a problem that I'm sure was not an issue previously.

I have a Customer object with and Address object, I can bind up to all the properties of the customer (including the address for display) but when the formview binds back it throws an exception say that property Adress.AddressLine1 cannot be found.

After some surfing it appears that Bind does not support nested objects yet eval does - this would be why I'm getting a display of the values but able to bind back.

Is it possible to use two way binding to nested objects?

Some Code: The Customer object:

    public Customer()
    {
        Address = new Address();
        DeliveryAddress = new Address();
    }

    public virtual int MemberNumber { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual string Phone { get; set; }
    public virtual string Email { get; set; }

    public virtual Address Address { get; set; }
    public virtual Address DeliveryAddress { get; set; }

The FormView code:

<asp:TextBox ID="AddressLine1" runat="server" Text='<%# Bind("Address.Address1") %>' />

The exception:


Could not find a property named 'Address.Address1' on the type specified by the DataObjectTypeName property in ObjectDataSource 'obsRegister'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Could not find a property named 'Address.Address1' on the type specified by the DataObjectTypeName property in ObjectDataSource 'obsRegister'.


I know I could use a parametrized method or nested controls/forms but I would have thought that directly accessing a nested object for data binding would have been a very common activity (especially in an OO world).

Thanks for any help