I’m using a FormView to edit my business objects. I don’t have any problem to edit/insert single properties.
Some of the business objects have collection properties that I’d like edit/insert in the same way I do for the single properties: Text='<%# Bind("SinglePropertyName") %>'.
So I’d like to include a gridview inside of the edit/insert templates and bind (two-way) it Datasource to the collection property: Datasource='<%# Bind("CollectionPropertyName") %>'. Then I’d like to be able to edit the collection propties items with the gridview itself and get the changed values among the other sigleproperties’ changes.
This works fine to show the template, the collection is rendered to the gridview. The problem is to get the changes on it.
I’ve tried to do so with no luck, I get the following exception when trying to Databind the gridview: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Beside that, the NewValues of the FormView for the CollectionProperty from the ItemUpdating event always return null.
So I’d like to see a working example of a similar scenario to see if I’m able to do it or if I need to use a different approach.
Thanks!
I already found a solution to this and it was to encapsulate the gridview in a user control (ObjectList) that exposes a Value property to bind to.
ObjectList.ascx:
ObjectList.ascx.cs:
I hope this help you if you deal with something like that.