<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Chris Forbes blogs on SharePoint &#38; .NET &#187; Lookup</title>
	<atom:link href="http://chrisforbesblogs.net/tag/lookup/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisforbesblogs.net</link>
	<description>Developers chat on SharePoint and .NET</description>
	<lastBuildDate>Fri, 23 Jul 2010 14:23:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='chrisforbesblogs.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/3aa4775025bad14a027d0ade34632a33?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Chris Forbes blogs on SharePoint &#38; .NET &#187; Lookup</title>
		<link>http://chrisforbesblogs.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://chrisforbesblogs.net/osd.xml" title="Chris Forbes blogs on SharePoint &#38; .NET" />
	<atom:link rel='hub' href='http://chrisforbesblogs.net/?pushpress=hub'/>
		<item>
		<title>Custom Lookup Fields</title>
		<link>http://chrisforbesblogs.net/2009/03/15/custom-lookup-fields/</link>
		<comments>http://chrisforbesblogs.net/2009/03/15/custom-lookup-fields/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:49:26 +0000</pubDate>
		<dc:creator>Chris Forbes</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Custom Lookup Field]]></category>
		<category><![CDATA[FLDTYPES.XML]]></category>
		<category><![CDATA[Lookup]]></category>
		<category><![CDATA[LookupMulti]]></category>
		<category><![CDATA[RenderPattern]]></category>

		<guid isPermaLink="false">http://chrisforbesblogs.wordpress.com/2009/03/15/custom-lookup-fields/</guid>
		<description><![CDATA[I was working on a client project recently and was using the out of the box SharePoint Lookup fields to manage ‘admin lists’ Basically allowing the user’s to manage the contents of their own drop down list fields. But the problem with the out of the box look up field is that it displays the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrisforbesblogs.net&blog=6742676&post=41&subd=chrisforbesblogs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I was working on a client project recently and was using the out of the box SharePoint Lookup fields to manage ‘admin lists’ Basically allowing the user’s to manage the contents of their own drop down list fields. </p>
<p>But the problem with the out of the box look up field is that it displays the value in the list views and when reading an&#160; item as a Hyperlink. So when the user click the link they get taken to the linked item, which in this case, is just an admin list with one field in it. So they kind of get lost!</p>
<p>This doesn&#8217;t improve usability of the application so I did some investigating and came up with the following solution. If anyone has any other ideas on how to achieve this I’d love to hear from you.</p>
<p>The following screen shots illustrate the solution you can see the lookup field is now display <em>without</em> the hyperlink to the corresponding lookup list, this is also the case when the list item is displayed in read mode.</p>
<p><a href="http://chrisforbesblogs.files.wordpress.com/2009/03/image4.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="40" alt="image" src="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb4.png?w=335&#038;h=40" width="335" border="0" /></a>&#160;</p>
<p>&#160;</p>
<p><em>Field being displayed without the hyperlink.</em></p>
<p><a href="http://chrisforbesblogs.files.wordpress.com/2009/03/image1.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="46" alt="image" src="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb1.png?w=197&#038;h=46" width="197" border="0" /></a>&#160;</p>
<p><a href="http://chrisforbesblogs.files.wordpress.com/2009/03/image2.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="49" alt="image" src="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb2.png?w=256&#038;h=49" width="256" border="0" /></a> </p>
<p>&#160;</p>
<p>After looking at the FLYTYPES.XML file found in the …12\TEMPLATE\XML directory of SharePoint I located the ‘Lookup’ field definition…</p>
<p><span class="kwrd"><font face="Arial">&lt;Field Name=&quot;TypeName&quot;&gt;Lookup&lt;/Field&gt;</font></span></p>
<p><span class="kwrd">If you look at it’s RenderTemplate and in particular the ‘DisplayPattern’ you will see this is where the anchor tag is added.</span></p>
<p><span class="kwrd"></span></p>
<p><span class="kwrd">So, my solution was to create your own custom field&#160; which has a parent type of Lookup and then define your own RenderPattern without any anchor tags.</span></p>
<p><span class="kwrd"></span></p>
<p>You can do this by using the visual studio extensions for SharePoint. After creating a new solution add a new Field Control</p>
<p>&#160;</p>
<p><a href="http://chrisforbesblogs.files.wordpress.com/2009/03/image3.png"><img title="image" style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" height="285" alt="image" src="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb3.png?w=462&#038;h=285" width="462" border="0" /></a> </p>
<p> Then in the field definition I defined the following field….</p>
<p>&#160;</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">FieldType</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TypeName</span>&quot;<span style="color:blue;">&gt;</span>LookupNoLinkField<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TypeDisplayName</span>&quot;<span style="color:blue;">&gt;</span>LookupNoLinkField<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TypeShortDescription</span>&quot;<span style="color:blue;">&gt;</span>Lookup (No Link)<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">ParentType</span>&quot;<span style="color:blue;">&gt;</span>Lookup<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">UserCreatable</span>&quot;<span style="color:blue;">&gt;</span>FALSE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FieldTypeClass</span>&quot;<span style="color:blue;">&gt;</span>7710ed2c-00e2-40e8-92dc-ea8ee5197138<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FieldEditorUserControl</span>&quot;<span style="color:blue;">&gt;</span>/_controltemplates/LookupFieldEditor.ascx<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">SQLType</span>&quot;<span style="color:blue;">&gt;</span>int<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Sortable</span>&quot;<span style="color:blue;">&gt;</span>TRUE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Filterable</span>&quot;<span style="color:blue;">&gt;</span>TRUE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">ShowInListCreate</span>&quot;<span style="color:blue;">&gt;</span>TRUE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">RenderPattern </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">DisplayPattern</span>&quot;<span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">LookupColumn </span><span style="color:red;">HTMLEncode</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TRUE</span>&quot; <span style="color:blue;">/&gt;
  &lt;/</span><span style="color:#a31515;">RenderPattern</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">FieldType</span><span style="color:blue;">&gt;</span></pre>
<p>Ok so because nothing in life is easy, there is a nice Gotcha! If either through the UI or through the API design to change this field now to allow multiv values then what actually happens is the field type is change to LookupMulti. So back comes your anchor tags. So you need to do the same thing but this time base you new custom field to parent the LookupMulti type.</p>
<p><span style="color:blue;">&lt;</span><span style="color:#a31515;">FieldType</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TypeName</span>&quot;<span style="color:blue;">&gt;</span>LookupNoLinkMultiField<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TypeDisplayName</span>&quot;<span style="color:blue;">&gt;</span>LookupNoLinkMultiField<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TypeShortDescription</span>&quot;<span style="color:blue;">&gt;</span>Lookup-Multi (No Link)<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">ParentType</span>&quot;<span style="color:blue;">&gt;</span>LookupMulti<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">UserCreatable</span>&quot;<span style="color:blue;">&gt;</span>FALSE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FieldTypeClass</span>&quot;<span style="color:blue;">&gt;</span>63aa539e-d34e-4858-bb93-c659103713f1<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">FieldEditorUserControl</span>&quot;<span style="color:blue;">&gt;</span>/_controltemplates/LookupFieldEditor.ascx<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">SQLType</span>&quot;<span style="color:blue;">&gt;</span>int<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Sortable</span>&quot;<span style="color:blue;">&gt;</span>TRUE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">Field </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">Filterable</span>&quot;<span style="color:blue;">&gt;</span>TRUE<span style="color:blue;">&lt;/</span><span style="color:#a31515;">Field</span><span style="color:blue;">&gt;<br />
    <br />&#160; &lt;</span><span style="color:#a31515;">RenderPattern </span><span style="color:red;">Name</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">DisplayPattern</span>&quot;<span style="color:blue;">&gt;<br />
    <br />&#160;&#160;&#160; &lt;</span><span style="color:#a31515;">LookupColumn </span><span style="color:red;">HTMLEncode</span><span style="color:blue;">=</span>&quot;<span style="color:blue;">TRUE</span>&quot; <span style="color:blue;">/&gt;<br />
    <br />&#160; &lt;/</span><span style="color:#a31515;">RenderPattern</span><span style="color:blue;">&gt;<br />
    <br />&lt;/</span><span style="color:#a31515;">FieldType</span><span style="color:blue;">&gt;</span></p>
<p><span style="color:blue;"></span>&#160;</p>
<p>With the solution I was building I was changing the field type to allow multi values…</p>
<p><font size="2"></p>
<p>lookupField.AllowMultipleValues = </p>
<p>  <font color="#0000ff" size="2"><font color="#0000ff" size="2">true</font></font><font size="2">;</font></font></p>
<p><font size="2">this resulted in the field reverting to the standard lookup field types. So how do you change this to be your customer lookup field.</font></p>
<p><font size="2"></font></p>
<p><font size="2">Well to begin with I looked at the method <em>SPField.Type</em> which takes an enumeration value <em>SPFieldType.</em> So here was my problem, what do you put here when is a custom field??</font></p>
<p><font size="2">I solved this by altering the <em>SchemaXml</em> property of the field. </font></p>
<p><font size="2"></font></p>
<p><font size="2"></p>
<p>lField.SchemaXml = lField.SchemaXml.Replace(</p>
<p>  <font color="#a31515" size="2"><font color="#a31515" size="2">&quot;LookupMulti&quot;</font></font><font size="2">, </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;LookupNoLinkMultiField&quot;</font></font><font size="2">)</font></font></p>
<p>This ensures your custom field is used and not the standard field. Let me know if you have any other solutions for this.</p>
<p>&#160;</p>
<p><font size="2"></font></p>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ba25f1a5-7c54-4a6d-b8fc-8ee5d857a506" style="display:inline;float:none;margin:0;padding:0;">del.icio.us Tags: <a href="http://del.icio.us/popular/Sharepoint" rel="tag">Sharepoint</a>,<a href="http://del.icio.us/popular/FLDTYPES.XML" rel="tag">FLDTYPES.XML</a>,<a href="http://del.icio.us/popular/Lookup" rel="tag">Lookup</a>,<a href="http://del.icio.us/popular/LookupMulti" rel="tag">LookupMulti</a>,<a href="http://del.icio.us/popular/Custom+Lookup+Field" rel="tag">Custom Lookup Field</a>,<a href="http://del.icio.us/popular/RenderPattern" rel="tag">RenderPattern</a></div></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrisforbesblogs.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrisforbesblogs.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrisforbesblogs.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrisforbesblogs.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrisforbesblogs.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrisforbesblogs.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrisforbesblogs.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrisforbesblogs.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrisforbesblogs.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrisforbesblogs.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrisforbesblogs.net&blog=6742676&post=41&subd=chrisforbesblogs&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://chrisforbesblogs.net/2009/03/15/custom-lookup-fields/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed3e25ef8a88f8fff819a7722f1805a9?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">chrisforbesblogs</media:title>
		</media:content>

		<media:content url="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://chrisforbesblogs.files.wordpress.com/2009/03/image-thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>