Sharepoint lookups over 20 items solution?
// May 7th, 2009 // Sharepoint
Came up with a super frustrating “by design” issue today which baffled me for hours.
The Problem
Ok, so i admit. I have a lookup on a Manaufacturers list which grabs me a list of cars (not really but we’ll use the example for simplicity). Ive built a custom list form and some “dodgy javascript” such that i can select the correct car in the Cars list when the New Form opens using the CARID querystring item. All worked perfectly until i hit 20 Cars!
Yes i admit that dodgy javascript isnt correct, but doesnt anyone find it a little strange that after 20 items, the lookup changes to a weird “input” type of control? Well that obviously broke my javascript. I needed a way to maintain the dropdownlist such that the javascript would keep filtering based on CARID.
The Solution
I sorta knew what i needed to do with this problem. I needed to change the Sharepoint:FormField item, i just didnt know how. After a LOAD of testing i came up with this. Ill try to document my changes as best as possible.
1. Your current lookup field in your custom list form probably looks something like this:
<SharePoint:FormField runat="server" id="ff9{$Pos}" ControlMode="New" FieldName="Related_x0020_Car" __designer:bind="{ddwrt:DataBind('i',concat('ff9',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Related_x0020_Car')}"/><br />
Do these steps in order otherwise this wont work
2. In the datasources add in the following datasource. Be careful to tell the datasource exactly what you are looking for:
a) change the DefaultValue attribute below to the name of your lookup list
<SharePoint:SPDataSource id="Cars1" runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="<View></View>"><SelectParameters><br />
<WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Cars"/><br />
</SelectParameters><br />
</SharePoint:SPDataSource>
3. Change the <SharePoint:FormField> to <SharePoint:DVDropDownList>
3. Add in the following attributes:
DataSourceID=”Cars1″
DataTextField=”Title” – the name of the column you lookup to
DataValueField=”ID”
SelectedValue=”{@Related_x0020_Car}” – the name of your lookup column
4. Remove
ControlMode
FieldName
5. Change
__designer:bind="{ddwrt:DataBind('i',concat('ff9',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Related_x0020_Car')}"
to
__designer:bind="{ddwrt:DataBind('i',concat('ff9',$Pos),'SelectedValue','SelectedIndexChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Related_x0020_Car')}"
where ‘i’ in the databind is for insert, i think ‘u’ is for update on editing forms
also, remember to use the correct id, mine is “ff9″ here but you may be different.
5. Thats it, should be done. It should now render as a dropdown which you can choose once again.
Hope this helped!









Great tip! I am currently fighting against these strange lookups with more than 20 items that render weird. But my problem is in the NewForm.aspx, because I have to manipulate the data there. If the lookup ha sless than 20 items, I can do everything; still, when it has miore than 20 items, I can’t access fields, even though I have the ID of the lookup and have control of it. I surfed the web and found that this can be solved with “ShowDropdown” function provided by Sharepoint, but this does not work. Do you have any suggestion on how to get control and access data of the lookup with more than 20 items in the NewForm.aspx? This is causing me really bad headaches! I beg you!
Fantastic blogging, thank you very much.
I was following a similar tutorial on the MSDN site which i couldnt get to work, but this has done the trick.
I ended up spending 3 days writing a workaround (i couldnt use the combolist with ‘ShowDropdown’ as the client didnt like the different rendering) which involved using javascript to populate a placeholder drop-down with the required values after AJAX updates updated a linked drop-down.
This would have saved me a lot of time!
PS: See my blog post on how to avoid doing these custom changes in SharePoint Designer in a production environment: http://thepointyheads.com/2009/10/custom-list-editform-deploy-the-easy-way/
Hi! Relly great tip. Very nice.
I have an additional question: how should I make this work, when I try to implement it in the edit mode.
Thanks again.
use Jquery and in the masterpage, paste :
jQuery(document).ready(function() {
AbsLeft = function(obj) { }
AbsTop = function(obj) { }
});
In the css, paste :
#_Select
{
width:250px;
margin-left:-250px;
margin-top:18px;
}
Great tip saved my day.
God bless you