Populate a Drop-Down List Box via a Secondary Data Source - Greg Collins

InfoPath Dev

This Blog


Greg Collins

Populate a Drop-Down List Box via a Secondary Data Source

One great feature of InfoPath SP1 is the ability to quickly populate a drop-down list box from a variety of data sources. One such data sources is an XML file that has been added to the form as a secondary data source. A common mistake is binding the Drop-down List Box control to the wrong data source.

Secondary data sources are very helpful to keep your main data source clean and pure for holding only essential form data. The values in the secondary data source may be updated during the life of the form, but they are never saved as part of the form. Only the values in the main data source are stored when the form is saved or published.

Binding is something that takes place between a control (such as a Drop-Down List Box) and a data node. When you select a data node in the Data Source task pane and drag it into the view, or right-click and choose a control type, the control in the view is "bound" to that data node--meaning that any value held by the control will be the stored value in the data node.

If a control is bound to a secondary data source, the stored value will persist for the life of the form. Once the form is closed, however, the value is lost. If a control is bound to the main data source, the value will be persisted as part of the saved form.

To correctly use a secondary data source to populate a Drop-Down List Box and have the selected value stored as part of the same form, the control needs to be bound to the main data source, but populated from the secondary data source. This can be done with the following steps:

Insert a Drop-Down List Box control bound to the main data source:

  1. From the Data Source task pane, select Main from the Data Source drop-down list.
  2. Select the data node you want the value to be stored in, right-drag it into the view, and then release in the location where you want the control placed.
  3. From the context menu that appears when you release the right-drag, select Drop-Down List Box.

Populate the Drop-Down List Box from a secondary data source:

  1. Double-click the Drop-Down List Box control.
  2. In the Drop-Down List Box Properties dialog box select Look Up Values In A Data Connection.
  3. Choose the secondary data source from the Data Connection drop-down list.
  4. Click the Select XPath button to the right of the Entries field.
  5. Select the node that will be used to populate the values, and then click OK.
  6. If necessary, use the Select XPath buttons to the right of the Value and Display Name fields to make appropriate node changes.
  7. Click OK to close the dialog box.

Your drop-down list is ready. Its values will be populated from the secondary data source, but the selected value will be stored in the main data source when the form is saved or published.

©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.



mkoram said:


can you tell me how to populate a listbox by querying the database either using code behind infopath or using a webservice.

Thank you

September 10, 2008 12:43 PM
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.