2

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.

4

1 回答 1

1

您可以将服务器控件的数据源绑定到父对象的属性。

此代码可能不是 100% 正确,但类似这样

<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>

假设您将 FormView 绑定到具有属性地址的对象,该属性地址是更多对象的集合。

于 2009-07-08T19:59:43.140 回答