Home > Products > BPC PowerForms - Silverlight > Knowledge Base > Controls > Using the DataEntryGrid to save to separate lists

Using the DataEntryGrid to save to separate lists

The DataEntryGrid control is used to allow users define a field structure and store complex information inside a multi-line text column formatted in XML.

In many cases, there is a requirement to keep this information in a separate list instead of storing an xml formatted value in a list column. Users need to add the master record and its related detail records with a single "Save" action, without having to save the master record first and then add the detail records one by one.

For example, the user wants to add a new order and provide the order lines at the same time, while the order lines are stored in a separate list.

DataEntryGrid has a new working mode that allows users to achieve this. Instead of storing the results in XML format, the control keeps track of every change in the detail grid (insertions, updates, deletions) and sends the information to the server along with the changes in the master record. This allows a single action to persist multiple list items in the back end.

To do that a user has to do the following :

  • Create a list query that will provide the control with its detail information
  • Define the list query criteria that will retrieve only the related records from the detail list
  • Define the fields for the DataEntryGrid control using the column names of the detail list
  • Bind the control's value to the list query
  • Define values of the DataEntryGrid that will be automatically set (for example the parent ID)
  • A special keyword : {ParentID} can be used to allow the control to set the ID of the master record to a value of all the detail records
  • The above will happen even if we are inserting a new record. The system will first insert the master record, get its ID and then use it to update every detail record provided.



We have 3 lists :

Products (ID, Title)

Orders (ID, Title, OrderDate)

OrderLines (ID, Title, ParentOrder, Product, Quantity)

NOTE : The ParentOrder column of the OrderLines list is a lookup column referencing the Orders list. The Product column of the OrderLines list is a lookup column referencing the Products list.

After registering PowerForms for th Orders list this is what you will get :

We now have to create a list query that will retrieve the related OrderLines.

Switch to the designer, go to List Queries and define a list query using the settings below :

 Note that we uncheck the "Ignore Blank Criteria" option since we do not want to get all order lines when the c_ID control is blank (for new orders).

Now we switch to the run time designer and add our DataEntryGrid control and set its height to 200.

We open control properties and in the "Value" tabm we bind its value to the list query we have just defined.

We now have to create the controls we will use for editing the order lines.

The DataEntryGrid grid, allows users to use hidden controls of the parent form. So we will create the required controls and mark them as hidden so that the control can use them when required.

We create a Label control for the OrderLineID named "c_DEG_ID" (no need to edit that). Then a LookupPicker control for the product named "c_DEG_Product" and finally a NumberTextBox for the quantity named "c_DEG_Quantity".

Spefically for the c_DEG_Product lookup control we have to define its lookup parameters in order for it to load products.

We then hide those three controls and setup the DataEntryGrid control properties.

In the Extra configuration of the control we add 3 fields :

Name = ID, Type = Existing, Header = ID, Width = 70, ExistingControlName = c_DEG_ID

Name = Product, Type = Existing, Header = Product, Width = 150, ExistingControlName = c_DEG_Product, DisplayForms = DisplayField (we just want to show the Title - not the ID)

Name = Quantity, Type = Existing, Header = Quantity, Width = 80, ExistingControlName = c_DEG_Quantity

We also select InlineEditing to allow faster data entry for the users.


Since we want the ParentOrder field to be automatically filled by the control, we add a new Value :

Name = ParentOrder

Value = {ParentID}

 We then save the designer and we get our new form :

In the above screenshot, we are inserting a new order and select to add 2 order lines for that order.

Obviously the order line ID is blank since these are new records.

Since we press the Save button, the system will first insert the order and then use the ID of the new order record to persist the provided order lines.

Our form after saving the order record :

And if you visit the OrderLines list we will verify that our 2 order lines are there and connected with the new Order record.

 Even when editing the order record, the control will keep track of all changes made to the order lines (new, deleted, modified) and persist them only if the users decides to update the order record.