Пример #1
0
        protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            if (!Enabled)
            {
                return(false);
            }

            int newSelectedIndex = Convert.ToInt32(postCollection.GetValues(HiddenFieldControl.UniqueID)[0], CultureInfo.InvariantCulture);

            EnsureDataBound();

            if (newSelectedIndex == -2 && (DropDownStyle == ComboBoxStyle.Simple || DropDownStyle == ComboBoxStyle.DropDown))
            {
                string newText = postCollection.GetValues(TextBoxControl.UniqueID)[0];
                ComboBoxItemInsertEventArgs eventArgs = new ComboBoxItemInsertEventArgs(newText, ItemInsertLocation);
                this.OnItemInserting(eventArgs);
                if (!eventArgs.Cancel)
                {
                    this.InsertItem(eventArgs);
                }
                else
                {
                    TextBoxControl.Text = (SelectedIndex < 0) ? string.Empty : SelectedItem.Text;
                }
            }

            else if (newSelectedIndex != SelectedIndex)
            {
                SelectedIndex = newSelectedIndex;
                return(true);
            }

            return(false);
        }
Пример #2
0
 protected void ComboBox1_ItemInserted(object sender, AjaxControlToolkit.ComboBoxItemInsertEventArgs e)
 {
     // user has inserted a new item into the demo combobox
     FeedbackItemInsertedLabel.Text    = String.Format(FeedbackItemInsertedLabel.Text, ComboBox1.SelectedItem.Text);
     FeedbackPanel.Visible             = true;
     FeedbackItemInsertedLabel.Visible = true;
 }
Пример #3
0
        protected virtual void OnItemInserted(ComboBoxItemInsertEventArgs e)
        {
            EventHandler <ComboBoxItemInsertEventArgs> handler = (EventHandler <ComboBoxItemInsertEventArgs>)Events[EventItemInserted];

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #4
0
        protected virtual void InsertItem(ComboBoxItemInsertEventArgs e)
        {
            if (!e.Cancel)
            {
                var insertIndex = -1;

                if (e.InsertLocation == ComboBoxItemInsertLocation.Prepend)
                {
                    insertIndex = 0;
                }
                else if (e.InsertLocation == ComboBoxItemInsertLocation.Append)
                {
                    insertIndex = Items.Count;
                }
                else if (e.InsertLocation == ComboBoxItemInsertLocation.OrdinalText)
                {
                    // loop through items collection to find proper insertion point
                    insertIndex = 0;
                    foreach (ListItem li in Items)
                    {
                        int compareValue = string.Compare(e.Item.Text, li.Text, StringComparison.Ordinal);
                        if (compareValue > 0)
                        {
                            ++insertIndex;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else if (e.InsertLocation == ComboBoxItemInsertLocation.OrdinalValue)
                {
                    // loop through items collection to find proper insertion point
                    insertIndex = 0;
                    foreach (ListItem li in Items)
                    {
                        int compareValue = string.Compare(e.Item.Value, li.Value, StringComparison.Ordinal);
                        if (compareValue > 0)
                        {
                            ++insertIndex;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (insertIndex >= Items.Count)
                {
                    Items.Add(e.Item);
                    SelectedIndex = Items.Count - 1;
                }
                else
                {
                    Items.Insert(insertIndex, e.Item);
                    SelectedIndex = insertIndex;
                }
                OnItemInserted(e);
            }
        }
Пример #5
0
 protected virtual void OnItemInserting(ComboBoxItemInsertEventArgs e)
 {
     EventHandler<ComboBoxItemInsertEventArgs> handler = (EventHandler<ComboBoxItemInsertEventArgs>)Events[EventItemInserting];
     if (handler != null)
         handler(this, e);
 }
Пример #6
0
        protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            if (!Enabled)
                return false;

            int newSelectedIndex = Convert.ToInt32(postCollection.GetValues(HiddenFieldControl.UniqueID)[0], CultureInfo.InvariantCulture);
            EnsureDataBound();

            if (newSelectedIndex == -2 && (DropDownStyle == ComboBoxStyle.Simple || DropDownStyle == ComboBoxStyle.DropDown))
            {
                string newText = postCollection.GetValues(TextBoxControl.UniqueID)[0];
                ComboBoxItemInsertEventArgs eventArgs = new ComboBoxItemInsertEventArgs(newText, ItemInsertLocation);
                this.OnItemInserting(eventArgs);
                if (!eventArgs.Cancel)
                {
                    this.InsertItem(eventArgs);
                }
                else
                {
                    TextBoxControl.Text = (SelectedIndex < 0) ? string.Empty : SelectedItem.Text;
                }
            }

            else if (newSelectedIndex != SelectedIndex)
            {
                SelectedIndex = newSelectedIndex;
                return true;
            }

            return false;
        }
Пример #7
0
        protected virtual void InsertItem(ComboBoxItemInsertEventArgs e)
        {
            if (!e.Cancel)
            {
                var insertIndex = -1;

                if (e.InsertLocation == ComboBoxItemInsertLocation.Prepend)
                {
                    insertIndex = 0;
                }
                else if (e.InsertLocation == ComboBoxItemInsertLocation.Append)
                {
                    insertIndex = Items.Count;
                }
                else if (e.InsertLocation == ComboBoxItemInsertLocation.OrdinalText)
                {
                    // loop through items collection to find proper insertion point
                    insertIndex = 0;
                    foreach (ListItem li in Items)
                    {
                        int compareValue = string.Compare(e.Item.Text, li.Text, StringComparison.Ordinal);
                        if (compareValue > 0)
                        {
                            ++insertIndex;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else if (e.InsertLocation == ComboBoxItemInsertLocation.OrdinalValue)
                {
                    // loop through items collection to find proper insertion point
                    insertIndex = 0;
                    foreach (ListItem li in Items)
                    {
                        int compareValue = string.Compare(e.Item.Value, li.Value, StringComparison.Ordinal);
                        if (compareValue > 0)
                        {
                            ++insertIndex;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (insertIndex >= Items.Count)
                {
                    Items.Add(e.Item);
                    SelectedIndex = Items.Count - 1;
                }
                else
                {
                    Items.Insert(insertIndex, e.Item);
                    SelectedIndex = insertIndex;
                }
                OnItemInserted(e);
            }
        }