Microsoft Infopath Tutorial and Online Training Course
Binding Controls
Controls need to be bound to a data source in order to save the data that users enter. A data source is a collection of fields that stores the data collected and used by the form.
By default, when you create a new, blank form, InfoPath creates a new XML data source. The fields in the data source are automatically bound to your controls. You can bind the controls to an existing data source instead, such as an existing XML Schema, XML document, database, or Web service; this will be covered later in the tutorial.
For now, view the data source InfoPath created for you using the Data Source task pane: On the Controls task pane, click Data Source. This option is also available on the Design Tasks task pane.
The Data Source task pane opens, displaying fields that correspond to the controls you added to the form. If you click on a control, the corresponding field is highlighted in the list.
Asterisks indicate the fields that cannot be left blank by the user.
When you include repeating and optional sections, the fields contained in each section correspond to fields located within a group. The group corresponds to the section itself:
Any time you delete a control from the form, the field InfoPath created remains in the list on the Data Source task pane. You can delete the field, if you won’t be using it, by selecting Delete from the field’s drop-down menu:
Populating Controls from a Data Source
Some controls, like list boxes, need to be populated with data, so the user can select an item. There are two ways to populate a control. The first is by manually entering the values using the Data tab of the Properties dialog. The second, and easier way, is to populate the control using a secondary data source. To demonstrate this, we’ll use the drop-down list box control:
Double-click a drop-down list box control to open the Drop-Down List Box Properties dialog.
On the Data tab, under List box entries, select Look up in a database, Web service, or file.
Click the Secondary Data Source button.
In the Secondary Data Sources dialog, click the Add button.
This opens the Data Source Setup Wizard again.
Use the wizard to locate and select the data source. This can be a database, an XML file or Schema, or a Web service. When you’re done, click Finish to close the wizard.
Click Close to close the Secondary Data Source dialog.
The secondary data source should now appear in the Data source field of the Drop-Down List Box Properties dialog:
Populating Controls from a Data Source (Continued)
Click the Select XPath button next to the Entries field.
This opens the Select a Field or Group dialog:
Select the group that contains the values you want and click OK.
The group now appears in the Entries field of the Drop-Down List Box Properties dialog:
Right now, the value is bound to the ID field in the table, which is fine. But the ID field is also bound to the display text of the list box. To make the list box display the corresponding text value, rather than the ID, click the Select XPath button next to the Display name field.
In the Select a Field or Group dialog, select the field that contains the text you want to display:
Click OK.
Click OK to close the Drop-Down List Box Properties dialog.
Preview the form by clicking the Preview Form button on the Standard toolbar.
If you check the binding of the control, by right-clicking the control and selecting Change Binding from the shortcut menu, you can see that the control is still bound to the original field—not to the field that’s populating it. This means that whatever value the user selects will be captured.