在 Edit/InsertTemplate 工作示例中带有 gridview 的 Asp.net Formview
我正在使用 FormView
来编辑我的业务对象。我编辑/插入单个属性没有任何问题。
某些业务对象具有集合属性,我希望以与单个属性相同的方式编辑/插入这些属性:Text='<%# Bind("SinglePropertyName") %>'
。
因此,我想在编辑/插入模板中包含一个 gridview 并将其数据源绑定(双向)到集合属性: Datasource='<%# Bind("CollectionPropertyName") %>'
。然后我希望能够使用 gridview 本身编辑集合属性项,并获取其他 sigleproperties 更改中的更改值。
这可以很好地显示模板,集合将呈现到网格视图。问题是要对其进行更改。
我尝试这样做,但没有成功,在尝试对 gridview 进行数据绑定时出现以下异常:数据绑定方法,例如 Eval()
、XPath()
和Bind()
只能在数据绑定控件的上下文中使用。
除此之外,ItemUpdating
事件中 CollectionProperty
的 FormView 的 NewValues 始终返回 null。
因此,我想查看类似场景的工作示例,看看我是否能够做到这一点,或者是否需要使用不同的方法。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到了解决方案,它将 gridview 封装在用户控件 (ObjectList) 中,该控件公开要绑定的 Value 属性。
ObjectList.ascx:
ObjectList.ascx.cs:
如果您处理类似的问题,我希望这对您有所帮助。
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.