internal static List <ListItem> GetAvailableValues(FilteredLookupField f, HttpContext ctx)
        {
            List <ListItem>      _v    = null;
            SPListItemCollection items = null;
            Guid fId = new Guid(f.LookupField);

            SPSite s          = SPControl.GetContextSite(ctx);
            SPWeb  lookupWeb  = s.OpenWeb(f.LookupWebId);
            SPList lookupList = lookupWeb.Lists[new Guid(f.LookupList)];

            try { if (f.QueryFilter != null)
                  {
                      items = lookupList.GetItems(f.QueryFilter);
                  }
            }
            catch { }
            if (items == null)
            {
                items = lookupList.Items;
            }

            if ((items != null && items.Count > 0))
            {
                _v = items
                     .Cast <SPListItem>()
                     .Where(e => e[fId] != null)
                     .Select(e => new ListItem((
                                                   e.Fields[fId].GetFieldValueAsText(e[fId])), e.ID.ToString()))
                     .ToList <ListItem>();
            }

            return(_v);
        }
        public void InitializeWithField(SPField field)
        {
            EnsureChildControls();
            FilteredLookupField _f = null;

            try { _f = field as FilteredLookupField; }
            catch { }

            if (_f != null)
            {
                // this bit only happens when field is not null
                if (!IsPostBack)
                {
                    cbxAllowMultiValue.Checked = _f.AllowMultipleValues;
                    txtQueryFilter.Text        = (!string.IsNullOrEmpty(_f.QueryFilterAsString)) ?
                                                 SPHttpUtility.HtmlDecode(_f.QueryFilterAsString) : string.Empty;
                    cbxRecursiveFilter.Checked = _f.IsFilterRecursive;
                    TargetWebId      = _f.LookupWebId.ToString();
                    TargetListId     = _f.LookupList;
                    TargetColumnId   = _f.LookupField;
                    TargetListViewId = _f.ListViewFilter;
                }
            }

            // this bit must always happen, even when field is null
            if (!IsPostBack)
            {
                SetTargetWeb();
                lblTargetWeb.Text  = listTargetWeb.SelectedItem.Text;
                lblTargetList.Text = listTargetList.SelectedItem.Text;
                SetControlVisibility();
            }
        }
Beispiel #3
0
    protected override void CreateChildControls() {
      // 19 items is limit for switching from
      // standard dropdown to SharePoint fancy dropdown
      if (base.Field != null && base.ControlMode != SPControlMode.Display) {
        if (!this.ChildControlsCreated) {
          this.Controls.Clear();
          this.Controls.Add(new LiteralControl("<span dir=\"none\">"));
          FilteredLookupField field = base.Field as FilteredLookupField;

          if (_availableItems != null && _availableItems.Count > 19 && IsExplorerOnWin()) {
            CreateCustomSelect();
          }
          else { CreateStandardSelect(); }
          this.Controls.Add(new LiteralControl("<br /></span>"));
        }
      }
    } 
        public void OnSaveChange(SPField field, bool isNewField)
        {
            FilteredLookupField _f = null;

            try { _f = field as FilteredLookupField; }
            catch { }

            if (_f != null)
            {
                string s    = txtQueryFilter.Text;
                bool   rec  = cbxRecursiveFilter.Checked;
                string view = (listTargetListView.SelectedIndex > -1) ?
                              listTargetListView.SelectedItem.Value : string.Empty;
                string col   = listTargetColumn.SelectedItem.Value;
                string list  = listTargetList.SelectedItem.Value;
                bool   multi = cbxAllowMultiValue.Checked;

                if (isNewField) // can only change list and web if new field
                {
                    SPSite _site = SPControl.GetContextSite(this.Context);
                    SPWeb  _web  = _site.OpenWeb(new Guid(listTargetWeb.SelectedItem.Value));
                    _f.LookupWebId = _web.ID;
                    _f.LookupList  = list;
                }

                if (rdFilterOption.SelectedItem.Value == "Query")
                {
                    _f.QueryFilterAsString = (!string.IsNullOrEmpty(s)) ? SPHttpUtility.HtmlEncode(s) : "";
                    _f.ListViewFilter      = "";
                }
                else if (rdFilterOption.SelectedItem.Value == "ListView")
                {
                    _f.ListViewFilter      = (!string.IsNullOrEmpty(view)) ? view : "";
                    _f.QueryFilterAsString = "";
                }

                _f.LookupField       = col;
                _f.IsFilterRecursive = rec;
                _f.UnlimitedLengthInDocumentLibrary = cbxUnlimitedLengthInDocLib.Checked;
                _f.CountRelated        = IsCountRelated(_f.LookupField, _f.LookupList);
                _f.AllowMultipleValues = (_f.CountRelated) ? false : multi;
            }
        }
        protected override void CreateChildControls()
        {
            if (this.Field != null && this.ControlMode != SPControlMode.Display)
            {
                if (!this.ChildControlsCreated)
                {
                    FilteredLookupField field = this.Field as FilteredLookupField;
                    base.CreateChildControls();

                    MultiLookupPicker = (GroupedItemPicker)TemplateContainer.FindControl("MultiLookupPicker");
                    BuildAvailableItems(ref MultiLookupPicker);

                    SelectCandidate = (SPHtmlSelect)TemplateContainer.FindControl("SelectCandidate");
                    SelectResult    = (SPHtmlSelect)TemplateContainer.FindControl("SelectResult");

                    AddButton    = (HtmlButton)TemplateContainer.FindControl("AddButton");
                    RemoveButton = (HtmlButton)TemplateContainer.FindControl("RemoveButton");
                }
            }
        }