Display Multiple Fields in a Drop-Down List Box - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Display Multiple Fields in a Drop-Down List Box

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.

Published Jul 08 2004, 02:33 PM by Greg Collins
Filed under: ,

Comments

 

Infopath 2007 Multi-select List Box w/ Multiple Columns | keyongtech said:

Pingback from  Infopath 2007 Multi-select List Box w/ Multiple Columns | keyongtech

January 22, 2009 1:54 AM
 

kalpesh.vaghela said:

Hi Greg Collins

I have tried "Approach 2"  this in my InfoPath form it works fine

But i need to publish this form in sharepoint form library

so i need to create browser enabled form

and this approach does not work in browser enabled form.

March 22, 2014 5:27 AM
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.