Exemplo n.º 1
0
        /// <summary>
        /// Creates any child controls necessary to render the field, such as a label control, link control, or text box control.
        /// </summary>
        protected override void CreateChildControls()
        {
            AutocompleteLookupField lookupFieldPicker = (AutocompleteLookupField)this.Field;

            using (SPWeb web = Web.Site.OpenWeb(lookupFieldPicker.LookupWebId))
            {
                SPList lookupList           = web.Lists[new Guid(lookupFieldPicker.LookupList)];
                AutocompleteControl control = Page.LoadControl(autocompleteAscxPath) as AutocompleteControl;
                Controls.Add(control);
                this.lookupEditor = control.FindControl("autocomplete") as TextBox;
                this.lookupIDs    = control.FindControl("LookupIDs") as HiddenField;
                string        lookupListName = lookupList.Title;
                StringBuilder listBuilder    = ValidateListOrFieldName(lookupListName);
                lookupListName         = listBuilder.ToString();
                control.LookupListName = lookupListName;
                string        internalFieldName = ((SPFieldLookup)(lookupFieldPicker)).LookupField;
                string        lookupFieldName   = lookupList.Fields.GetField(internalFieldName).Title;
                StringBuilder fieldBuilder      = ValidateListOrFieldName(lookupFieldName);
                lookupFieldName         = fieldBuilder.ToString();
                control.LookupFieldName = lookupFieldName;
                control.SiteUrl         = web.Url;
                control.Filter          = Filter ?? lookupFieldPicker.GetFieldAttribute("Filter");
                if (lookupFieldPicker.AllowMultipleValues)
                {
                    control.IsMultiLookup = true;
                }
                else
                {
                    control.IsMultiLookup = false;
                }
            }

            base.CreateChildControls();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the field control value.
        /// </summary>
        /// <param name="value">The value.</param>
        private void SetFieldControlValue(object value)
        {
            this.lookupEditor.Text = string.Empty;
            AutocompleteLookupField lookupFieldPicker = (AutocompleteLookupField)this.Field;

            if (this.ControlMode == SPControlMode.New && lookupEditor.Text.Length == 0)
            {
                //string strValue = ParseDefaultValue(lookupFieldPicker.CustomDefaultValue);

                //if (strValue == null)
                return;
            }
            else
            {
                if (value == null || value.ToString() == "")
                {
                    return;
                }

                if (lookupFieldPicker.AllowMultipleValues)
                {
                    SPFieldLookupValueCollection lookupValues = value as SPFieldLookupValueCollection;
                    foreach (SPFieldLookupValue lookupValue in lookupValues)
                    {
                        string text = new SPFieldLookupValue(lookupValue.ToString()).LookupValue;
                        this.lookupEditor.Text += text + "; ";

                        int ID = new SPFieldLookupValue(lookupValue.ToString()).LookupId;

                        this.lookupIDs.Value += text + "[" + ID + "]" + "; ";
                    }
                }
                else
                {
                    SPFieldLookupValue lookupValue = value as SPFieldLookupValue;
                    this.lookupEditor.Text = lookupValue.LookupValue;
                    this.lookupIDs.Value   = this.lookupEditor.Text + "[" + lookupValue.LookupId + "]";
                }
            }
        }