Monday, September 8, 2008

Sharepoint Lookup Column - Get multiple values

In this post, I will show you how to display lookup column data in a multiple selection format.

Steps:

1. I have a list called 'ATSCompany' which has a lookup column called 'Video' which references a document library called 'ATSCompany Videos'. Notice that I have selected the 'Allow multiple values' checkbox.

2. Edit a list item of the ATSCompany list, here is what it looks like.


3. After you have selected all 3 videos, the value of the video column is a string containing all the three video file name separated by semicolon.

4. In Sharepoint designer, I have created a custom list form for viewing the ATSCompany List. Right click the List and go to List Properties, you can see that I have specified CompanyProfile.aspx as the view item page for the ATSCompany Page. More
details.



5. In the CompanyProfile.aspx, it should displays three links which link to the videos in the 'ATSCompany Videos' document library.


6. In the Sharepoint designer, under the WebPartPages:dataformwebpart of the ATSCompany List. You will have the following to show the video links. Note that template ParseVideoString makes a recursive call to itself.

1 <xsl:if test=" string-length(@Video) &gt;0" ddwrt:cf_ignore="1">


2 <div>


3 <br />


4 <h3>Videos</h3>


5 <xsl:call-template name="ParseVideoString">


6 <xsl:with-param name="parse-string" select="@Video" />


7 </xsl:call-template>


8 </div>


9 </xsl:if>



1 <xsl:template name="ParseVideoString">


2 <xsl:param name="parse-string"></xsl:param>


3 <xsl:if test="not($parse-string='')">


4 <xsl:choose>


5 <xsl:when test="contains($parse-string, ';')">


6 <a href="../ATSCompany Videos/{substring-before($parse-string, ';')}" ><xsl:value-of select="substring-before($parse-string, ';')"/></a><br /></xsl:when>


7 <xsl:otherwise>


8 <a href="../ATSCompany Videos/{$parse-string}" ><xsl:value-of select="$parse-string"/></a></xsl:otherwise>


9 </xsl:choose>


10 <xsl:call-template name="ParseVideoString">


11 <xsl:with-param name="parse-string">


12 <xsl:value-of select="substring-after($parse-string, ';')"/>


13 </xsl:with-param>


14 </xsl:call-template>


15 </xsl:if>


16 </xsl:template>


blog comments powered by Disqus