private void Initialize_multi_value(CustomDropDownList clist) { try { SPWeb w = SPContext.Current.Site.OpenWeb(clist.LookupWebId); SPList list = w.Lists[new Guid(clist.LookupList)]; if (list != null && list.ItemCount > 0 && list.Fields.Contains(new Guid(clist.LookupField))) { SPListItemCollection Items = null; string viewId = string.Empty; if (Convert.ToString(clist.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty) { viewId = Convert.ToString(clist.GetCustomProperty(CustomDropDownList.VIEW)); viewId = viewId.Substring(0, viewId.IndexOf('|')); SPView view = list.GetView(new Guid(viewId)); string view_query = view.Query; string view_order_query = string.Empty; SPQuery query = new SPQuery(); query.ViewAttributes = "Scope=\"RecursiveAll\""; bool use_view_order = Convert.ToBoolean(clist.GetCustomProperty(CustomDropDownList.SORT_BY_VIEW)); if (use_view_order) { string xml = string.Format("<Query>{0}</Query>", view.Query); XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlNode node = document.DocumentElement.SelectSingleNode("OrderBy"); if (node == null || string.IsNullOrEmpty(node.InnerXml)) { //do nothing } else { view_order_query = node.InnerXml; } view_order_query = string.Format("<OrderBy>{0}</OrderBy>", view_order_query); } if (view_query.Contains("<Where>")) { int start_index = view_query.IndexOf("<Where>") + "<Where>".Length; int length = view_query.IndexOf("</Where>") - start_index; view_query = view_query.Substring(start_index, length); query.Query = "<Where>" + view_query + "</Where>" + view_order_query; Items = list.GetItems(query); } else { query.Query = view_order_query; Items = list.GetItems(query); } } else { Items = list.Items; } _availableItems = new List<ListItem>(); _ItemsList_Multi_NoLink = new List<ListItem>(); foreach (SPListItem item in Items) { ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(clist.LookupField)].GetFieldValueAsText(item[new Guid(clist.LookupField)])), item.ID.ToString()); if (!this._availableItems.Contains(newItem)) { this._availableItems.Add(newItem); _ItemsList_Multi_NoLink.Add(newItem); } } } } catch { } }
public static void FetchMatchedValuesFromList(CustomDropDownList field, string sel_value, ref List <ListItem> item_list) { SPListItemCollection matched_items = null; string viewId = string.Empty; bool use_view_order = false; if (Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty) { viewId = Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)); viewId = viewId.Substring(0, viewId.IndexOf('|')); use_view_order = Convert.ToBoolean(field.GetCustomProperty(CustomDropDownList.SORT_BY_VIEW)); } using (SPWeb w = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId)) { SPList list1 = w.Lists[new Guid(((SPFieldLookup)field).LookupList)]; string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN); SPField link_field = list1.Fields[new Guid(linked_column)]; SPQuery query = new SPQuery(); if (string.IsNullOrEmpty(viewId)) { query.Query = "<Where><Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></Where>"; } else { SPView view = list1.GetView(new Guid(viewId)); string view_query = view.Query; string item_query = "<Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></And>"; if (!string.IsNullOrEmpty(view_query) && view_query.Contains("<Where>") && view_query.Contains("</Where>")) { int start_index = view_query.IndexOf("<Where>") + "<Where>".Length; int length = view_query.IndexOf("</Where>") - start_index; view_query = view_query.Substring(start_index, length); view_query = "<Where><And>" + view_query + item_query + "</Where>"; string view_order_query = string.Empty; if (use_view_order) { string xml = string.Format("<Query>{0}</Query>", view.Query); XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlNode node = document.DocumentElement.SelectSingleNode("OrderBy"); if (node == null || string.IsNullOrEmpty(node.InnerXml)) { //do nothing } else { view_order_query = node.InnerXml; view_order_query = string.Format("<OrderBy>{0}</OrderBy>", view_order_query); } view_query += view_order_query; } query.Query = view_query; } else { query.Query = "<Where><Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></Where>"; } } matched_items = list1.GetItems(query); } foreach (SPListItem item in matched_items) { ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(((SPFieldLookup)field).LookupField)].GetFieldValueAsText(item[new Guid(((SPFieldLookup)field).LookupField)])), item.ID.ToString()); if (!item_list.Contains(newItem)) { item_list.Add(newItem); } } }
public static void FetchMatchedValuesFromList(CustomDropDownList field, string sel_value, ref List<ListItem> item_list) { SPListItemCollection matched_items = null; string viewId = string.Empty; bool use_view_order = false; if (Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty) { viewId = Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)); viewId = viewId.Substring(0, viewId.IndexOf('|')); use_view_order = Convert.ToBoolean(field.GetCustomProperty(CustomDropDownList.SORT_BY_VIEW)); } using (SPWeb w = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId)) { SPList list1 = w.Lists[new Guid(((SPFieldLookup)field).LookupList)]; string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN); SPField link_field = list1.Fields[new Guid(linked_column)]; SPQuery query = new SPQuery(); if (string.IsNullOrEmpty(viewId)) { query.Query = "<Where><Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></Where>"; } else { SPView view = list1.GetView(new Guid(viewId)); string view_query = view.Query; string item_query = "<Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></And>"; if (!string.IsNullOrEmpty(view_query) && view_query.Contains("<Where>") && view_query.Contains("</Where>")) { int start_index = view_query.IndexOf("<Where>") + "<Where>".Length; int length = view_query.IndexOf("</Where>") - start_index; view_query = view_query.Substring(start_index, length); view_query = "<Where><And>" + view_query + item_query + "</Where>"; string view_order_query = string.Empty; if (use_view_order) { string xml = string.Format("<Query>{0}</Query>", view.Query); XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlNode node = document.DocumentElement.SelectSingleNode("OrderBy"); if (node == null || string.IsNullOrEmpty(node.InnerXml)) { //do nothing } else { view_order_query = node.InnerXml; view_order_query = string.Format("<OrderBy>{0}</OrderBy>", view_order_query); } view_query += view_order_query; } query.Query = view_query; } else { query.Query = "<Where><Eq><FieldRef Name='" + link_field.InternalName + "' LookupId='TRUE'/><Value Type='Lookup'>" + sel_value + "</Value></Eq></Where>"; } } matched_items = list1.GetItems(query); } foreach (SPListItem item in matched_items) { ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(((SPFieldLookup)field).LookupField)].GetFieldValueAsText(item[new Guid(((SPFieldLookup)field).LookupField)])), item.ID.ToString()); if (!item_list.Contains(newItem)) { item_list.Add(newItem); } } }
public static void FetchAllValueFromLinkedList(CustomDropDownList field, ref List <ListItem> PopulateItems) { try { SPWeb spWeb = SPContext.Current.Site.OpenWeb(field.LookupWebId); SPList spFiedLookupList = spWeb.Lists[new Guid(field.LookupList)]; if (spFiedLookupList != null && spFiedLookupList.ItemCount > 0 && spFiedLookupList.Fields.Contains(new Guid(field.LookupField))) { SPListItemCollection Items = null; string viewId = string.Empty; if (Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty) { viewId = Convert.ToString(field.GetCustomProperty(CustomDropDownList.VIEW)); viewId = viewId.Substring(0, viewId.IndexOf('|')); SPView view = spFiedLookupList.GetView(new Guid(viewId)); string view_query = view.Query; string view_order_query = string.Empty; SPQuery query = new SPQuery(); query.ViewAttributes = "Scope=\"RecursiveAll\""; bool use_view_order = Convert.ToBoolean(field.GetCustomProperty(CustomDropDownList.SORT_BY_VIEW)); if (use_view_order) { string xml = string.Format("<Query>{0}</Query>", view.Query); XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlNode node = document.DocumentElement.SelectSingleNode("OrderBy"); if (node == null || string.IsNullOrEmpty(node.InnerXml)) { //do nothing } else { view_order_query = node.InnerXml; } view_order_query = string.Format("<OrderBy>{0}</OrderBy>", view_order_query); } if (view_query.Contains("<Where>")) { int start_index = view_query.IndexOf("<Where>") + "<Where>".Length; int length = view_query.IndexOf("</Where>") - start_index; view_query = view_query.Substring(start_index, length); query.Query = "<Where>" + view_query + "</Where>" + view_order_query; Items = spFiedLookupList.GetItems(query); } else { query.Query = view_order_query; Items = spFiedLookupList.GetItems(query); } } else { Items = spFiedLookupList.Items; } PopulateItems = new List <ListItem>(); foreach (SPListItem item in Items) { ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupField)].GetFieldValueAsText(item[new Guid(field.LookupField)])), item.ID.ToString()); if (!PopulateItems.Contains(newItem)) { PopulateItems.Add(newItem); } } } } catch { } }