Exemplo n.º 1
0
 /// <summary>
 /// Serializa un item a una cadena
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 /// <date>02/12/2013</date>
 /// <author>VAR</author>
 public static string Serialize(DropDownListItem item)
 {
     return(string.Format("{0};{1};{2};{3}",
                          item.Value.Replace("\\", "\\\\").Replace(";", "\\;"),
                          item.Text.Replace("\\", "\\\\").Replace(";", "\\;"),
                          item.InUse ? 1 : 0,
                          item.CssClass.Replace("\\", "\\\\").Replace(";", "\\;")));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Borra todos los items que tengan InUse a false, excepto el seleccionado
        /// </summary>
        /// <date>03/12/2013</date>
        /// <author>VAR</author>
        public void RemoveNotInUse()
        {
            int i = 0;

            if (_multiselection == false)
            {
                while (i < _items.Count)
                {
                    if (i == _selectedIndex)
                    {
                        i++; continue;
                    }
                    if (!_items[i].InUse)
                    {
                        _items.RemoveAt(i);
                        if (_selectedIndex > i)
                        {
                            _selectedIndex--;
                        }
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                while (i < _items.Count)
                {
                    DropDownListItem selectedItem = null;
                    for (int j = 0; j < _selectedItems.Count; j++)
                    {
                        if (_selectedItems[j].Value == _items[i].Value)
                        {
                            selectedItem = _selectedItems[j];
                            break;
                        }
                    }
                    if (selectedItem != null)
                    {
                        i++; continue;
                    }
                    if (!_items[i].InUse)
                    {
                        _items.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
Exemplo n.º 3
0
 public override void LoadData(DataTable dt)
 {
     _items.Clear();
     SelectedIndex = -1;
     if (dt == null || dt.Rows.Count <= 0)
     {
         Enabled = false;
         return;
     }
     foreach (DataRow dr in dt.Rows)
     {
         DropDownListItem item = ItemFormDataRow(dr);
         if (_translateItems)
         {
             item.Text = item.Text;
         }
         _items.Add(item);
     }
     if (_sortByText)
     {
         _items.Sort((a, b) => a.Text.CompareTo(b.Text));
     }
     if (_multiselection == false)
     {
         if (string.IsNullOrEmpty(_defaultItemText))
         {
             _items.Insert(0, new DropDownListItem {
                 Text = "SelectOne", Value = string.Empty
             });
         }
         else
         {
             _items.Insert(0, new DropDownListItem {
                 Text = _defaultItemText, Value = string.Empty
             });
         }
     }
     Enabled = true;
     _loaded = true;
 }
Exemplo n.º 4
0
        private DropDownListItem ItemFormDataRow(DataRow dr)
        {
            var item = new DropDownListItem();

            if (!String.IsNullOrEmpty(_dataTextField) && dr.Table.Columns.Contains(_dataTextField))
            {
                item.Text = Convert.ToString(dr[_dataTextField]);
            }
            if (!String.IsNullOrEmpty(_dataValueField) && dr.Table.Columns.Contains(_dataValueField))
            {
                item.Value = Convert.ToString(dr[_dataValueField]);
            }
            if (!String.IsNullOrEmpty(_dataInUseField) && dr.Table.Columns.Contains(_dataInUseField))
            {
                item.InUse = true;
            }
            if (!String.IsNullOrEmpty(_dataCSSClassField) && dr.Table.Columns.Contains(_dataCSSClassField))
            {
                item.CssClass = Convert.ToString(dr[_dataCSSClassField]);
            }
            return(item);
        }
Exemplo n.º 5
0
        protected override object SaveViewState()
        {
            // Seriar items
            var    sbItems = new StringBuilder();
            string strItem = null;

            foreach (DropDownListItem item in _items)
            {
                if (strItem != null)
                {
                    sbItems.Append('|');
                }
                strItem = DropDownListItem.Serialize(item).Replace("|", "\\|");
                sbItems.Append(strItem);
            }
            ViewState["Items"]         = sbItems.ToString();
            ViewState["SelectedIndex"] = SelectedIndex;

            ViewState["Loaded"] = _loaded;

            return(base.SaveViewState());
        }
Exemplo n.º 6
0
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            // Deseriar items
            _items.Clear();
            var           strItems     = (string)ViewState["Items"];
            List <string> listStrItems = SplitUnscaped(strItems, '|');

            foreach (string strItem in listStrItems)
            {
                DropDownListItem item = DropDownListItem.Deserialize(strItem);
                if (item == null)
                {
                    continue;
                }
                _items.Add(item);
            }

            SelectedIndex = Convert.ToInt32(ViewState["SelectedIndex"]);

            _loaded = Convert.ToBoolean(ViewState["Loaded"]);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Obtiene el texto asignado a un valor
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <date>22/08/2014</date>
        /// <author>VAR</author>
        public string GetTextFromValue(string value)
        {
            DropDownListItem item = _items.FirstOrDefault(it => (it.Value == value));

            return(item != null ? item.Text : null);
        }
Exemplo n.º 8
0
 private void SetSelection(DropDownListItem item, int i)
 {
     _selectedItem  = item;
     _selectedIndex = i;
     Text           = SelectedText;
 }
Exemplo n.º 9
0
 private void ClearSelection()
 {
     _selectedItem  = null;
     _selectedIndex = -1;
     Text           = string.Empty;
 }