views:

44

answers:

1

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...

+1  A: 

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.

Jeroen
I kinda suspected as much, this is solution i've always used in the past for problems like these. It's very disappointing with all the effort and extolling Microsoft has put into the their lastest databinding controls, that they really can't solve a pedestrian problem such as this.
James