Exemplo n.º 1
0
        //internal static void BindListInternal(DropDownList comboBox, object value, IEnumerable listSource, string textField, string valueField)
        internal static void BindListInternal(DnnComboBox comboBox, object value, IEnumerable listSource, string textField, string valueField)
        {
            if (comboBox != null)
            {
                string selectedValue = !comboBox.Page.IsPostBack ? Convert.ToString(value) : comboBox.SelectedValue;

                if (listSource is Dictionary <string, string> )
                {
                    var items = listSource as Dictionary <string, string>;
                    foreach (var item in items)
                    {
                        //comboBox.Items.Add(new ListItem(item.Key, item.Value));
                        comboBox.AddItem(item.Key, item.Value);
                    }
                }
                else
                {
                    comboBox.DataTextField  = textField;
                    comboBox.DataValueField = valueField;
                    comboBox.DataSource     = listSource;

                    comboBox.DataBind();
                }

                //Reset SelectedValue
                //comboBox.Select(selectedValue);
                var selectedItem = comboBox.FindItemByValue(selectedValue);
                if (selectedItem != null)
                {
                    selectedItem.Selected = true;
                }
            }
        }
Exemplo n.º 2
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     this._moduleCombo = new DnnComboBox();
     this._moduleCombo.DataValueField = "key";
     this._moduleCombo.DataTextField  = "value";
     this.Controls.Add(this._moduleCombo);
 }
Exemplo n.º 3
0
        protected override WebControl CreateControlInternal(Control container)
        {
            //ComboBox = new DropDownList { ID = ID + "_ComboBox" };
            ComboBox = new DnnComboBox {
                ID = ID + "_ComboBox"
            };
            ComboBox.SelectedIndexChanged += IndexChanged;
            container.Controls.Add(ComboBox);

            if (ListSource != null)
            {
                BindList();
            }

            return(ComboBox);
        }