ObjectDataSource和FormView:如何从业务层添加UI编辑行为
我正在使用 ObjectDataSource 和 FormView。
在 FormView 中我有一组控件。当 FormView 处于编辑状态时,我特别有一个 ComboBox 和一个 TextBox,它们的相关关系如下: 当 ComboBox 接受一些特殊值时,TextBox 必须是只读的或非只读的。
目前,我得到的行为如下:当其所选项目发生更改时,组合框会触发回发,并且在页面的“OnPreRender”中,我获取组合框的值并相应地更新文本框的只读属性。
我不喜欢这种方法的是,我不使用由 ObjectDataSource 使用的对象模型。问题很简单,当 FormView 处于编辑状态时,似乎没有办法获取正在编辑的对象的实例。 “DataItem”为空,我还没有找到任何方法可以根据控件中的值自动构建新对象以将其传递到我的业务层。当然,我可以通过显式获取控件中的所有值来自己完成整个工作,但这并不好。
有人遇到过这样的场景吗?关于如何获得简洁的设计有什么想法吗?
I'm using an ObjectDataSource and a FormView.
In the FormView I have a set of controls. When the FormView is in edition, I have in particular a ComboBox and a TextBox which are related as follows:
when the ComboBox takes some special values, the TextBox must be read only or not.
For the moment I get that behaviour as follows: the ComboBox triggers a postback when its selected item is changed and in the 'OnPreRender' of my page I get the value of the ComboBox and update the Readonly property of the TextBox accordingly.
What I don't like with this method is that I don't use my object model which is consumed by the ObjectDataSource. The problem is simply that when the FormView is in edition there does not seem to be a way to get the instance of the object which is being edited. The 'DataItem' is null and I haven't found any way to automatically build a new object from the values in the controls to pass it to my business layer. Of course I could do the whole job myself by getting explicitly all the values in the controls, but that's not nice.
Has anybody ever met such a scenario ? Any ideas on how to get a clean design ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 DataItemIndex 或 DataKey 怎么样?我可能会使用 DataKey,然后使用业务方法来查找该键的对象。
How about using DataItemIndex or DataKey? I would probably use DataKey and then use the business method to look up for the object for the key.