Click here to Skip to main content
13,346,487 members (65,233 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 11 Oct 2006

How to create dynamically populated dropdown in an InfoPath Form

, 21 Jul 2010
Rate this:
Please Sign up or sign in to vote.
How to create dynamically populated dropdown in an InfoPath Form


Assume that a form needs to have a drop down list whose values are dynamically loaded dependent on the user's selection in another control and the solution should avoid problems with writing and maintaining a complex DOM manipulation script. Assume that the values for the drop down list should come from an external source like a database table or an XML file.

This document will go into the Indecomm Knowledge Base repository.

Sample Scenario

The user is presented with a Country drop down list. Depending on his choice, the City drop down list should be populated with Cities that are in the selected country.


An external data source will be created to access a relational data table or an XML file. Entries for the City drop down are filtered using a defined filter.

Step by step walk-through

  1. Create an XML file as follows and save it as Options.xml
    <?xml version="1.0" encoding="utf-8" ?>
    <Country CountryID="US" CountryName="United States">
        <City CityID="LAX" CityName="Los Angeles" /> 
        <City CityID="SEA" CityName="Seattle" />
    <Country CountryID="CA" CountryName="Canada">
        <City CityID="WPG" CityName="Winnepeg" />
        <City CityID="ONT" CityName="Ontario" />
  2. Open a new blank InfoPath form in design mode
  3. Save it as Country-City.xsn
  4. Go to Tools | Data Connections | Add | RecieveData | XMLDocument
  5. Select the Options.xml file
  6. Check Automatically Retrieve Data and click Finish.
    Note: This will allow you not to reload the Option.xml file.
  7. Create two Drop down boxes, named ddCountry and ddCity
  8. Double-click on ddCountry
  9. Check Lookup values in a data connection…
  10. Select Options in the Data Connection drop down.
  11. Click on Entries, select Country, click OK
  12. Select Value as CountryID and Name as CountryName
  13. Select Apply | OK
  14. Double-click on ddCity
  15. Check Lookup values in a data connection…
  16. Select Options in the Data Connection drop down.
  17. Click on Entries. Select City then click FilterData | Add
  18. Select City, is equal to,and ddCountry from Select a field or group | Main
  19. Press OK 3 times
  20. Select Value as CityID and Name as CityName
  21. Select Apply | OK
  22. We’re done..! Preview the form.

Note: If you would like to publish this form to public, you need to remove the security restrictions.

  1. Go to Menu | Tool | Forms Options | Security
  2. Uncheck Automatically determine security.
  3. Check the Full Trust option
  4. Check Sign this form and create or use a certificate.

Install this certificate on the client computer where you will use the form.


This simple solution helps to avoid using a DOM manipulation script, which is complex.


For any further information or queries contact me at

My Blog:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Canada Canada
Firoz Mohammed (Firoz`Ozman) |
MCSD.Net, MCTS (BizTalk 2004 & 2006)
Avanade Inc: |
Toronto, Canada |

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 21 Jul 2010
Article Copyright 2006 by FirozOzman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid