ASP.Net 主/详细信息与数据绑定到数据源对象 - 具有全有或全无原则的多重插入
我的目标是允许用户输入订单标题和详细数据,并通过单击一个按钮将其全部保存,在一次事务中,这样保存要么全部保存,要么什么都不保存。
例如:
Tables:
OrderHeader:
Id,
CustomerId,
Comments,
OrderDate,
OrderLine
Id,
OrderId FK => OrderHeader
ProductId,
Quantity
Markup (abbreviated):
<asp:FormView ID="uxFormHeaderInfo" runat="server" DataSourceID="headerDataSource">
<InsertItemTemplate>
<%--Header Fields--%>
.....
<asp:GridView ID="uxDetails" runat="server" DataSourceID="detailsDataSource">
<%-- Markup --%>
.....
</asp:GridView>
<asp:Button ID="uxSave" runat="server" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
在页面中,我有 FormView 控件,其中包含 CustomerId 和 Comments 的编辑字段,我还有一个嵌套的 gridview 或 listview,可以向其中添加行项目。 FormView 和 gridview 控件很可能链接到独立的数据源控件。我想要发生的是让用户输入标题信息和行项目,然后单击屏幕底部的“保存”一次。
使用 LinqDataSource 或 ObjectDatasource 对象是否可以实现这一点?如果是这样,您能否向我指出一个很好的示例,该示例展示了如何在主/详细样式插入中执行此操作,只需单击一个按钮即可命中 2 个或更多表格?提前致谢。
[编辑]
在查看了反馈并搜索了该主题后,我得出的结论是数据源控件不是完成这项工作的工具。由于他们无法真正处理像这样平淡无奇的案件,恕我直言,这确实让人质疑他们的用处。新方法就这么多了...
My goal is to allow the user to enter order header and detail data and have it all save with a single button click, in one transaction so the save is all or nothing.
For example:
Tables:
OrderHeader:
Id,
CustomerId,
Comments,
OrderDate,
OrderLine
Id,
OrderId FK => OrderHeader
ProductId,
Quantity
Markup (abbreviated):
<asp:FormView ID="uxFormHeaderInfo" runat="server" DataSourceID="headerDataSource">
<InsertItemTemplate>
<%--Header Fields--%>
.....
<asp:GridView ID="uxDetails" runat="server" DataSourceID="detailsDataSource">
<%-- Markup --%>
.....
</asp:GridView>
<asp:Button ID="uxSave" runat="server" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
In the page i'd have FormView control that will contain the edit fields for CustomerId and Comments, also i'd have a nested gridview or listview that I could add line items to. The FormView and gridview controls would most likely be linked to independent datasource controls. What I want to happen is for the user to enter the header info and the line items and click save just once at the bottom of the screen.
Is this even possible using the LinqDataSource or ObjectDatasource objects? If so could you point me to a good example that shows how to do this in master/detail style insert that hits 2 or more tables with a single button click? Thanks in advance.
[Edit]
After reviewing feedback and searching around on this subject, I've concluded that datasource controls are just the wrong tool for the job. Since they can't really handle a case as pedestrian as this, it really does call into question their usefulness IMHO. So much for the new way...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这不适用于数据源。至少据我所知不是。
我会自己处理保存操作。在保存按钮的 Click 事件中,读取用户输入的值,将其封装在事务中并调用您的业务函数。
I don't think this is going to work with a DataSource. At least not that i know of.
I would handle the Save operation myself. In the Click event of your save button read the values the user has entered, encapsulate it in a transaction and call your business functions.