Populating a Repeating Section from a Table


You can use Alpha Anywhere's Data Binding features to automatically populate a repeating section with data from an external table.

About Populating Repeating Sections

Data from an external DBF or SQL table can be placed in a repeating section through Data Binding. Repeating Sections require slightly more complex data binding than, for example, a simple textbox control that is bound to a given field in a SQL table. Instead of being bound to a specific field, repeating sections are tied to a table that is itself linked to a parent table and uses a OneToMany 'Link type'. The repeating section can then be used to display data in a child table of the table that the repeating section is bound to.

Repeating sections are frequently used to create an invoice or detail form based on a larger table. For example, say you have a 'Orders' table that defines a list of orders from different customers. A second table might display the details of the customers' orders and a third table the details of the products that were ordered. A repeating section bound to the 'Order Detail' table could be used to display product information from the Product about all of the products that were ordered by a given customer.


In order to link tables it is necessary to define a primary key. A primary key references the name of a field that is present in both tables. For example, the 'order' table and 'order detail' table might share a field named 'OrderID'. This field could then be defined as the primary key linking the two tables. You can use a different primary key to link the 'order detail' and 'product' tables, like 'ProductID'.


After the component has been bound to multiple tables, it is possible to bind the Repeating section to a table using the 'OnetoMany' Link type. In this example the Repeating section will be bound to the 'Order Details' table. The controls within the Repeating section can then be assigned to the fields in the Product table using a 'OnetoOne' Link type

In order to actually populate the Repeating section with data it will be necessary to create a populate action in the component's onDialogInitialize server-side event. When the UX component starts this event fires causing the action to run. The bound data is then transfered from the server-side table to the repeating section on the client-side.

For more on this subject watch this two part video: Part 1, Part 2, or follow the guides below.

Define a Repeating Section to Populate

  1. In the UX Builder on the UX Controls page open the 'Data Controls' menu and then click on the [TextBox] option to add a textbox control to the UX component. Give the textbox the name and label 'product_id'

    Pressing the 'Make label same as name' button at the bottom of the 'New Control' dialog will speed things up. TIP: In the Field Properties section set this control's Width to '1in'.
  2. Add a second [TextBox] control to the component with the name and label 'unit_price'.

    TIP: In the Field Properties section set this control's Width to '1in'.
  3. Add a third [TextBox] control with the name and label 'product_name'.

    TIP: In the Field Properties section set this control's Width to '3in'.
  4. Add a fourth [Textbox] control with the name and label 'units_in_stock'.

    TIP: In the Field Properties section set this control's Width to '1in'.
  5. Finally, add a fifth [TextBox] control with the name and label 'quantity_per_unit'.

    TIP: In the Field Properties section set this control's Width to '1.5in'.
  6. Highlight the five textbox controls and click the 'Toggle break' icon to turn off the toggle break between them.

  7. With the textboxes still highlighted, open the 'Containers' menu. Click on the [Container] option.

  8. From the 'Container Type' list select the 'RepeatingSection' option.

  9. The controls tree should look like this:

    Highlight the [RepeatingSection:REPEATINGSECTION_1] tab. In the properties list on the right set the 'Container width' property to 8 inches

Bind the Component to Data in Tables

  1. From the UX menu open the 'Data Binding' page and click on the Bind the controls on your UX to fields in one or more existing tables hyperlink.

  2. Click the 'Specify Tables' button.

  3. Click the 'Select' button at the bottom of the 'Select Table(s)' dialog.

  4. If you have a connection to the Northwind database check the 'Use a named connection string' radio button and then click 'Select...' and choose the Northwind connection. Otherwise check the 'Specify a connection string' option and build a connection. When you have a connection string Click OK.

  5. Click the 'Add table' button and then 'Select Table'.

  6. Choose the 'Orders' table and click OK and OK again.

  7. Click the 'Add table' button a second time. Make sure the 'Link type' dropdown at the bottom of the 'Add New Table' dialog is set to 'OnetoMany', then push 'Select Table' button again.

  8. Select the 'Order Details' table from the Northwind database and click OK and OK again.

  9. Click on the 'OrderDetails' table in the table tree.

  10. In the Link Properties section of the 'Select Table(s)' dialog click the [...] button next to the 'Parent link fields' property and select OrderID.

  11. The 'Link fields' property and the 'Primary key field(s)' property should be filled automatically.

  12. Click the 'Add Table' button a third time. This time set the 'Link type' dropdown to be 'OneToOne'.

  13. Click the 'Select Table...' button. Select the 'Products' table and then click OK and OK again.

  14. Highlight the 'Products' table on the 'Select Table(s)' dialog's tables tree. Click the [...] button next to the 'Parent link fields' property.

  15. Select the 'ProductID' field and click OK

  16. Click OK to exit the 'Select Table(s)' dialog.

Bind the Table to the Repeating Section

  1. In the UX Builder open the Data Binding page. Click on the 'Bind the controls on your UX to fields in one or more existing tables' hyperlink.

  2. Click the 'Bind Tables to Repeating Sections' button.

  3. Click on the 'REPEATINGSECTION_1' dialog section and select the 'OrderDetails' table. Click OK.


Assigning Variables to Fields

  1. In the 'Bind UX Controls to Table Fields' dialog click the 'Bind UX Component Controls to Table Fields' button.

  2. In the UX Section list at the top highlight the 'REPEATINGSECTION_1' option.

  3. A variable list will appear. Click on the 'product_id' variable.

  4. Assign the 'product_id' variable to the 'ProductID(N)' field and click OK

  5. Click on the 'unit_price' variable and assign it to the UnitPrice(N) field.

  6. Assign the 'product_name' variable to the 'ProductName(C)' field.

  7. Assign the 'units_in_stock' variable to the UnitsInStock(N) field.

  8. Finally assign the 'quantity_per_unit' variable to the 'QuantityPerUnit(C)' field. Click OK and OK again to exit.


Assigning an Action to Populate the Repeating Section

  1. In the Events menu open the 'Server-side' events page. In the Server-side Events menu click on the onDialogInitialize event.

  2. Place the mouse cursor inside the onDialogInitialize function by clicking anywhere inside the function definition.

  3. Click on the 'Action Scripting' icon in the top-right corner of the toolbar.

  4. Click on and highlight the 'Populate a Dialog with data from one or more tables' action. Click OK.

  5. The 'Populate Dialog with Data from One or More Table(s)' dialog will appear. Click the dropdown next to the Primary key source setting, in the 'Populate Dialog Settings', and select 'SpecifyNow'.

  6. Set the 'Primary key value' to '10250'. This is a random entry from the list of Order IDs in the OrderID field. Click OK.

  7. Run the component in Live Preview. All of the product information related to the 10250 order should be visible in the Repeating section.


Variables Containing Primary Keys