Showing posts with label Lookup Field. Show all posts
Showing posts with label Lookup Field. Show all posts

Wednesday, August 29, 2012

Lookup field dropdown position issue

I was trying to create a custom webpart that will display a form to submit data in a list. The list had few lookup fields.
Whenever, I click on that image it displays us with a drop-down containing all the values, but the funniest part is you can select a particular item either by double click or by selecting it once and clicking it else where on the page or by tabbing system of the keyboard. But I want it work like a normal drop-down selection in other words just with a single click and also the control should be closer to other controls from usability perspective.


To fix this issue. you need to set InDesign ="true";

 Ex.BaseFieldControl webControl = field.FieldRenderingControl;

webControl.ID =
string.Format("ctrl_{0}_{1}", field.InternalName, pplCount);


webControl.FieldName = field.Title;

webControl.ItemContext =
SPContext.GetContext(HttpContext.Current, lstReqData.DefaultView.ID, lstReqData.ID, lstReqData.ParentWeb);

webControl.RenderContext = SPContext.GetContext(HttpContext.Current, lstReqData.DefaultView.ID, lstReqData.ID, lstReqData.ParentWeb);

webControl.ControlMode = SPControlMode.New;

webControl.ListId = lstReqData.ID;

webControl.InDesign =
true;

 If you are using form field you can set it by following changes in aspx page

<SharePoint:FormField runat="server" InDesign="true" ID="myFieldId" ControlMode="New" FieldName="myFieldName" />