Adf.Web.Binding.DropDownListBinder.Bind C# (CSharp) Method

Bind() public method

Populates the specified System.Web.UI.WebControls.DropDownList with the specified list using the specified parameters.
public Bind ( object control, IEnumerable values ) : void
control object The /// to bind to.
values IEnumerable The list to bind.
return void
        public virtual void Bind(object control, IEnumerable values, params object[] p)
        {
            if (values == null) return;

            var ddl = control as DropDownList;
            if (ddl == null) return;

            ddl.Items.Clear();

            var selectval = string.Empty;
            if (p != null && p.Length > 0) selectval = (p[0] is IDomainObject) ? (p[0] as IDomainObject).Id.ToString() : p[0].ToString();

            foreach (var value in values)
            {
                var text = (value is Enum) ? (value as Enum).GetDescription() : value.ToString();
                var val = (value is IDomainObject) ? (value as IDomainObject).Id.ToString() : text;

                var listItem = new ListItem(text, val);

                if (p != null && p.Length > 0)
                {
                    listItem.Selected = val == selectval;
                }

                ddl.Items.Add(listItem);
            }

            if (p != null && p.Length > 0)
            {
                if (ddl.SelectedValue.IsNullOrEmpty() && !p[0].ToString().IsNullOrEmpty())
                    ddl.Items.Insert(0, new ListItem("<invalid value>") { Selected = true });
            }
        }

Same methods

DropDownListBinder::Bind ( object control, object values ) : void
DropDownListBinder::Bind ( object control, object value, PropertyInfo pi ) : void
DropDownListBinder