public void InitializeWithField(SPField field) { EnsureChildControls(); CascadingLookupField _f = null; try { _f = field as CascadingLookupField; } catch { } if (_f != 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; } } if (!IsPostBack) { SetTargetWeb(); lblTargetWeb.Text = listTargetWeb.SelectedItem.Text; lblTargetList.Text = listTargetList.SelectedItem.Text; SetControlVisibility(); } }
public void OnSaveChange(SPField field, bool isNewField) { CascadingLookupField _f = null; try { _f = field as CascadingLookupField; } 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) { 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 = false; _f.AllowMultipleValues = (_f.CountRelated) ? false : multi; } }
protected override void CreateChildControls() { if (this.Field != null && this.ControlMode != SPControlMode.Display) { if (!this.ChildControlsCreated) { CascadingLookupField field = this.Field as CascadingLookupField; 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"); } } }
protected override void CreateChildControls() { Initialize(); if (base.Field != null && base.ControlMode != SPControlMode.Display) { if (!this.ChildControlsCreated) { this.Controls.Clear(); this.Controls.Add(new LiteralControl("<span dir=\"none\">")); CascadingLookupField field = base.Field as CascadingLookupField; if (_availableItems != null && _availableItems.Count > 19 && IsExplorerOnWin()) { CreateCustomSelect(); } else { CreateStandardSelect(); } this.Controls.Add(new LiteralControl("<br /></span>")); } } }
internal static List <ListItem> GetAvailableValues(CascadingLookupField f, BaseFieldControl thisfield) { List <ListItem> _v = null; List <SPListItem> items = new List <SPListItem>(); Guid fId = new Guid(f.LookupField); SPList lookupList = SPContext.Current.Web.Lists[new Guid(f.LookupList)]; try { if (f.QueryFilter != null) { SPQuery query = new SPQuery(); query.Query = f.QueryFilter.Query; Regex regex = new Regex(@"\[(.[^\[\]]+)"); foreach (string coluna in regex.Matches(query.Query).OfType <Match>().Select(m => m.Groups[1].Value) .Where(m => m.ToUpper() != "HOJE" && m.ToUpper() != "EU")) { BaseFieldControl ctr = GetFieldControlByName(thisfield, coluna); if (!(ctr is MultipleCascadingLookupFieldControl) && !(ctr is CascadingLookupFieldControl) && ctr.Controls[0] != null) { if (ctr.Controls[0] is ListControl) { (ctr.Controls[0] as ListControl).AutoPostBack = true; } else if (ctr.Controls[0] is TextBox) { (ctr.Controls[0] as TextBox).AutoPostBack = true; } } string value = string.Empty; if (ctr != null) { if (ctr.Value is SPFieldLookupValue) { value = ((SPFieldLookupValue)ctr.Value).LookupId.ToString(); } else { value = ctr.Value.ToString(); } } else if (SPContext.Current.ListItem != null) { value = SPContext.Current.ListItem[coluna].ToString(); } query.Query = query.Query.Replace(string.Format("[{0}]", coluna), value); } items = lookupList.GetItems(query).OfType <SPListItem>().ToList(); } else { items = lookupList.Items.OfType <SPListItem>().ToList(); } } catch { } //if (items.Count <= 0) { items = lookupList.Items.OfType<SPListItem>().ToList(); } try { if (items.Count > 0) { _v = items .Cast <SPListItem>() .Where(e => e[e.Fields[fId].InternalName] != null) .Select(e => new ListItem(( e.Fields[fId].GetFieldValueAsText(e[fId])), e.ID.ToString())) .ToList <ListItem>(); } } catch { } return(_v); }