// May 7th, 2009 // 3 Comments » // 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!