Programmer's Corner Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programmer's Corner - Forums


FormView

 
Post new topic   Reply to topic    Programmer's Corner Forum Index -> ASP.NET 2.0
Author Message
bdi
Nobody


Joined: 21 Oct 2004
Posts: 1646
Location: Chicago

PostPosted: Sun May 25, 2008 9:34 am    Post subject: FormView Reply with quote

I am trying to bind an ObjectDataSource to a FormView. The Object would be a person and has some properties like FirstName and LastName that work fine. The person object also has an Address property though which is a different class with address line 1, line 2, city, etc in it. Can I use the FormView to bind to those as well?

The best option I have come up with is to create a property in the person class for each of the fields I want to bind to in the Address class. I also thought of using inheritance and having a base object, but there are several objects needed, not just address.

Is there a better way?
Back to top
DiskJunky
Grasshopper


Joined: 11 Jun 2004
Posts: 17

PostPosted: Thu May 29, 2008 3:51 am    Post subject: Reply with quote

I'm not sure if this would work but you could create a dummy object like this;
Code:

public class Wrapper
{
    private PersonObject _person = new Person();
    private AddressObject _address = new Address();

    public Wrapper(PersonObject person, AddressObject address)
        : Base()
    {
        _person = person;
        _address = address;
    }

    public Person PersonDetails
    {
        get { return _person; }
        set { _person = value; }
    }

    public Address AddressDetails
    {
        get { return _address; }
        set { _address = value; }
    }
}

Then elsewhere in your code where you specify what you're binding to you put "Person.Name" or "Address.City". If that doesn't work you could try just "Name" and "City" and hope that the binding picks it up. If neither work then you'll need to create wrapper properties for the specific bits you want to expose like;
Code:

    public String Name
    {
        get { return _person.Name; }
        set { _person.Name = value; }
    }
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Programmer's Corner Forum Index -> ASP.NET 2.0 All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2002 phpBB Group