protected override void OnLoad(System.EventArgs e) { Sitecore.Diagnostics.Assert.IsNotNull(e, "e"); base.OnLoad(e); // if the drop-down is not yet populated, // populate it with the names of the agents if (this.SelectedAgent.Controls.Count < 1) { foreach (string agent in this.GetAgentNames()) { Sitecore.Web.UI.HtmlControls.ListItem entry = new Sitecore.Web.UI.HtmlControls.ListItem(); entry.Header = agent; entry.Value = agent; this.SelectedAgent.Controls.Add(entry); } foreach (string name in Enum.GetNames(typeof(System.Threading.ThreadPriority))) { Sitecore.Web.UI.HtmlControls.ListItem entry = new Sitecore.Web.UI.HtmlControls.ListItem(); entry.Header = name; entry.Value = name; this.Priority.Controls.Add(entry); this.Priority.Value = System.Threading.ThreadPriority.BelowNormal.ToString(); } } }
// sort the list of selected items protected void SortSelected() { // we need to know whether and by what to sort if (string.IsNullOrEmpty(this.SortBy)) { return; } // get the list of selected items string viewStateString = this.GetViewStateString("ID"); SC.Web.UI.HtmlControls.Listbox listbox = this.FindControl( viewStateString + "_selected") as SC.Web.UI.HtmlControls.Listbox; SC.Diagnostics.Assert.IsNotNull( listbox, typeof(SC.Web.UI.HtmlControls.Listbox)); // temporary list of items to sort List <SC.Web.UI.HtmlControls.ListItem> list = new List <SC.Web.UI.HtmlControls.ListItem>(); // populate temporary list from UI list for (int i = 0; i < listbox.Controls.Count; i++) { SC.Web.UI.HtmlControls.ListItem listItem = listbox.Controls[i] as SC.Web.UI.HtmlControls.ListItem; SC.Diagnostics.Assert.IsNotNull( listItem, typeof(SC.Web.UI.HtmlControls.ListItem)); list.Add(listItem); } // clear the UI list while (listbox.Controls.Count > 0) { listbox.Controls.RemoveAt(0); } // sort the temporary list list.Sort(this.Compare); // add the sorted list to the UI foreach (SC.Web.UI.HtmlControls.ListItem listItem in list) { listbox.Controls.Add(listItem); } // I couldn't find a case that required this, // but I included it in case you find such a case. SC.Web.UI.Sheer.SheerResponse.Refresh(listbox); }
// comparison method for sorting selected items protected int Compare( SC.Web.UI.HtmlControls.ListItem listItemA, SC.Web.UI.HtmlControls.ListItem listItemB) { SC.Diagnostics.Assert.IsNotNull(listItemA, "listItemA"); SC.Diagnostics.Assert.IsNotNull(listItemB, "listItemB"); // not too keen on this format string[] split = listItemA.Value.Split(new char[] { '|' }); if (split.Length != 2) { return(1); } SC.Data.Items.Item itemA = this.CurrentItem.Database.GetItem( split[1], this.CurrentItem.Language); if (itemA == null) { return(1); } split = listItemB.Value.Split(new char[] { '|' }); if (split.Length != 2) { return(-1); } SC.Data.Items.Item itemB = this.CurrentItem.Database.GetItem( split[1], this.CurrentItem.Language); if (itemB == null) { return(-1); } else if (this.SortBy == "@displayname") { return(string.Compare( itemA.DisplayName, itemB.DisplayName, StringComparison.InvariantCultureIgnoreCase)); } else if (this.SortBy == "@path") { return(string.Compare( itemA.Paths.FullPath, itemB.Paths.FullPath, StringComparison.InvariantCultureIgnoreCase)); } else if (this.SortBy == "@name") { return(string.Compare( itemA.Name, itemB.Name, StringComparison.InvariantCultureIgnoreCase)); } return(string.Compare( itemA[this.SortBy], itemB[this.SortBy], StringComparison.InvariantCultureIgnoreCase)); }