While developing your InfoPath form, you might need to have a drop-down list box display more information from more than one field. This is actually quite simple by manually modifying your view .xsl file. In this task we will demonstrate the changes necessary to display multiple fields in a single drop-down list box.
APPROACH 1:
The first approach is the easiest. It involves manually modifying the view .xsl file and using the XPath concat() function to display the combined values of multiple fields in the drop-down list box.
If, for example, you have XSL that looks something like this:
<option> <xsl:attribute name="value"> <xsl:value-of select="my:EmployeeId"/> </xsl:attribute> <xsl:if test="$val=my:EmployeeId"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:value-of select="my:LastName"/> </option> |
Modify the XSL (see the changes highlighted in red) to look something like this:
<option> <xsl:attribute name="value"> <xsl:value-of select="my:EmployeeId"/> </xsl:attribute> <xsl:if test="$val=my:EmployeeId"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:value-of select="concat(my:LastName, ', ', my:FirstName, ' (', my:EmployeeId, ')')"/> </option> |
These modifications will roundtrip in the designer. This means that when you load your form template in the designer, make changes to it, and then save it, these modifications will not be lost.
APPROACH 2:
The second, and potentially more robust, approach is to populate the drop-down list box via code. This technique is demonstrated in my example form: Fully Editable Drop-Down List Box. By using code, you can completely customize your drop-down list box.
©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.