InfoPath: Populating Fields from Drop-Down Selection
Published: 18 Aug 2004
Unedited - Community Contributed
This article explains how to populate a repeating table's current row fields based on a drop-down list selection in the same row in InfoPath.
by Michelle Beall
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30389/ 82


Building on my previous article, Setting Secondary Data Source Web Service parameters using C# at runtime in InfoPath, this example will demonstrate using a runtime-populated drop-down list in a repeating table to populate other fields in the same row.  This technique proves useful when building a table of parts in an order form for a given vendor as an example.

As with most things there is usually more than one way to perform a task, but this article will demonstrate achieving this form functionality by using built-in features of the InfoPath IDE.  This example leverages the following:

  •  Microsoft Office InfoPath 2003 Service Pack 1 (SP1) Preview

  • InfoPath 2003 Toolkit for Visual Studio .NET

  • Microsoft Visual Studio .NET 2003 (1.1 Framework)

  • Microsoft Visual C#

  • Web service running on IIS 6.0

Setting up the Example

Assume you want to call a Web service and pass in parameters supplied by the user at runtime.  The Web service will populate a drop-down list field in a repeating table.  The user should then be able to add rows at will to the repeating table and in each row make a selection from the drop-down list.  When the user selects an option, the corresponding repeating table row fields are populated with the correct data row values for the value selected. 

This example assumes the web service returns data in a structure similar to the following where all information related to a part number is in sibling nodes:

<font face="Verdana" color="black" size="2"><root>

Start by creating a new InfoPath project in Visual Studio.  In the InfoPath IDE add a text box, a repeating table with a drop-down list, and a text box with the following properties:

Text Box Name wsParam1
Data Type Text (string)
Drop-Down List Box Name field2
Data Type Text (string)
List box entries Lookup values in a data connection to the database, Web service, file, or SharePoint library or list
Text Box Name autofilledtext
Data Type Text (string)

Set up the drop-down list box to be populated dynamically at run time as described in Setting Secondary Data Source Web Service parameters using C# at runtime in InfoPath   We also need to add a hidden field to the main DOM with the following properties:

Name hdnSelectedVal
Data Type Text (string)
Rules and Actions

To populate the text box in the same row of the repeating table, open the properties dialog window of the drop-down list.  On the Data tab click on the Rules button.  We need to add two rules.  The first will set the value of the hidden field to the selected value of the active drop down list.  The second will use the hidden field value to filter the secondary data source and set the text box with a sibling node value.

Add a rule and then add a Set a field’s value action to the rule.  Select the hidden field as the field and set the value to the drop-down list’s current value (see Figure 1).  Click OK a couple times until you are back to the Rules window.

Figure 1
Figure 1

Add a second rule and then add another Set a field’s value action to this new rule.  Select the repeating table text box as the field.  To set the value click on the function button select Insert Field or Group and navigate to the secondary data source field you want the value of.  Then click on the Filter Data … button.  Add a filter to reflect the following condition:

[Secondary data source drop-down list value field] = [hidden field value]

Click OK a couple times until you are back to the Action window (see Figure 2) and then click OK a few more times to exit the drop-down list’s property dialog.

Figure 2
Figure 2

When you preview the form, you can now supply a parameter value to a web service.  The web service then populates the drop-down list in a repeating table row.  Select a value from the drop-down list and the text box in the same row will be populated with corresponding information.  This will work for every row added to the repeating table.


This example can be built upon to remove already selected items from the drop-down list when you add a new row to the repeating table in order to prevent a user from having two rows with the same selection in the table.  One method might be to use the built in validation features.  Another method might be to use XQuery.


User Comments

Title: great tip!   
Name: Schandmaul
Date: 2004-10-06 9:14:50 AM
thank you a lot

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2020  |  Page Processed at 2020-08-11 6:35:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search