Exemplo n.º 1
0
        public static HtmlElement SelectByEnum(string name, Type enumtype, string selectvalue, bool multiple, bool addnullitem)
        {
            Select select = (Select) new Select(multiple).Name(name);

            Select.SelectItem si;
            if (addnullitem)
            {
                si = new Select.SelectItem();
                if (string.IsNullOrEmpty(selectvalue))
                {
                    si.Selected = true;
                }
                select.Items.Add(si);
            }
            foreach (object item in Enum.GetValues(enumtype))
            {
                si       = new Select.SelectItem();
                si.Name  = item.ToString();
                si.Value = item.ToString();
                if (!string.IsNullOrEmpty(selectvalue))
                {
                    si.Selected = item.ToString() == Enum.Parse(enumtype, selectvalue).ToString();
                }
                select.Items.Add(si);
            }

            return(select);
        }
Exemplo n.º 2
0
        public static HtmlElement Select <T>(string name, System.Collections.IEnumerable data, EventSelectBind <T> bind, bool Multiple, bool addnullitem)
        {
            Select select = (Select) new Select(Multiple).Name(name);

            Select.SelectItem si;

            if (addnullitem)
            {
                si = new Select.SelectItem();
                select.Items.Add(si);
            }
            if (data != null && bind != null)
            {
                foreach (T item in data)
                {
                    si = new Select.SelectItem();
                    select.Items.Add(si);
                    bind(item, si);
                }
            }
            return(select);
        }