views:

1023

answers:

1

Hello,

I need to edit a complex object with complex properties using a web form. For example, editing a "User Information" record that contains all kinds of information about a user, including complex things like a unique tree for each user. What I did was this:

I created a web form with a Formview control, and set the object I want to bind as the Datasource of the Formview.

In the Formview templates I've put Usercontrols for binding each object property. The only thing I pass to the Usercontrol is the name of the property it's suppose to bind.

Inside the the Usercontrol I created server-side controls according to the type of property the Usercontrol is suppose to display. If it's a simple property like a string, I did something like this:

<asp:TextBox ID="textBox1" runat="server" Text='<%# Bind(PassedAttributeName) %>' />

And this works fine.

My problem is with the complex properties like things that suppose to appear in a treeview. I'm not really sure how am I suppose to bind the treeview inside my Usercontrol with a property of an object which is a Datasource of the containing Formview...

If you have an idea on how can this be done, or if you think I'm doing this whole thing wrong, any help will be appreciated.

Thanks.

+1  A: 

You can bind the datasource of a server control to a property of the parent object.

This code may not be 100% correct but something like so

<asp:FormView Id="formView1" runat="server">
    <asp:TextBox ID="textBox1" runat="server" Text='<%# Bind("FirstName")%>'/>
    <asp:Repeater ID="repeater1" runat="server" DataSource='<%# Bind("Addresses")%>'>
    //etc
    </asp:Repeater>
</asp:FormView>

Assuming that you bind the FormView to an object that has a Property Addresses which is a collection of more objects.

Bela