开发者

ASP.Net master/detail w/Databinding to DataSource objects - multi-insert with all-or-nothing principals

开发者 https://www.devze.com 2023-01-20 01:24 出处:网络
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.

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" CommandNa开发者_运维技巧me="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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消