예제 #1
0
        /// <summary>
        /// Edits the ListItems that were added or removed on the clientside
        /// </summary>
        /// <param name="postDataKey">The post data key.</param>
        /// <param name="postCollection">The post collection.</param>
        /// <returns>True if the list of items has changed.</returns>
        private Boolean loadNewItems(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            this.EnsureChildControls();
            String postedValue = postCollection[this.itemTracker.UniqueID];

            Boolean result = false;

            ArrayList currentSelection = this.SelectedIndicesInternal;

            if (postedValue != null && postedValue.Length != 0)
            {
                ListCommand[] commands = ListCommand.Split(postedValue.Trim());
                foreach (ListCommand command in commands)
                {
                    if (command.Operator == "+")
                    {
                        ListItem newItem = new ListItem(command.Text, command.Value);
                        if (command.Index >= 0 && command.Index <= this.Items.Count - 1)
                        {
                            this.Items.Insert(command.Index, newItem);
                        }
                        else
                        {
                            this.Items.Add(newItem);
                        }
                    }
                    else if (command.Operator == "-")
                    {
                        if (command.Index >= 0 && command.Index <= this.Items.Count - 1)
                        {
                            if (this.Items[command.Index].Selected)
                            {
                                result = true;
                            }
                            this.Items.RemoveAt(command.Index);
                        }
                    }
                }
            }

            if (!result)
            {
                ArrayList newSelection = this.SelectedIndicesInternal;
                if (newSelection == null)
                {
                    result = (currentSelection != null);
                }
                else
                {
                    if (newSelection.Count != currentSelection.Count)
                    {
                        result = true;
                    }
                    else
                    {
                        for (Int32 i = 0; i < currentSelection.Count; i++)
                        {
                            if ((Int32)newSelection[i] != (Int32)currentSelection[i])
                            {
                                result = true;
                                break;
                            }
                        }
                    }
                }
            }

            return(result);
        }