Ejemplo n.º 1
0
        /// <summary>
        /// Populates the specified <see cref="System.Web.UI.WebControls.DropDownList"/> with 
        /// the specified collection of values.
        /// </summary>
        /// <remarks>
        /// The supported types of items in the specified collection of values can be of type 
        /// Adf.Business.DomainObject, Adf.Core.Descriptor, System.Enum, SmartReference etc.
        /// </remarks>
        /// <param name="control">The <see cref="System.Web.UI.WebControls.DropDownList"/> 
        /// to bind to.</param>
        /// <param name="value">The collection of values to bind.</param>
        /// <param name="pi">The property used to check whether an empty item will be included in the 
        /// <see cref="System.Web.UI.WebControls.DropDownList"/>.</param>
        /// <param name="p">The parameters used for binding. Currently not being used.</param>
        public virtual void Bind(object control, object value, PropertyInfo pi, params object[] p)
        {
            if (value == null) return;

            var listBox = control as ListBox;
            if (listBox == null) return;

            listBox.Items.Clear();

            var includeEmpty = !pi.IsNonEmpty();

            foreach (var item in PropertyHelper.GetCollectionWithDefault(value, includeEmpty))
            {
                var listitem = new ListItem(item.Text, item.Value.ToString()) {Selected = item.Selected};

                listBox.Items.Add(listitem);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates the specified <see cref="System.Web.UI.WebControls.RadioButtonList"/> with 
        /// the specified collection of values using the specified parameters.
        /// </summary>
        /// <remarks>
        /// The supported types of items in the specified collection of values can be of type 
        /// Adf.Business.DomainObject, Adf.Business.SmartReferences.SmartReference&lt;T&gt;, 
        /// Adf.Core.Descriptor, System.Enum etc.
        /// </remarks>
        /// <param name="control">The <see cref="System.Web.UI.WebControls.RadioButtonList"/> 
        /// to bind to.</param>
        /// <param name="value">The collection of values to bind.</param>
        /// <param name="pi">The property used to check whether an empty item will be included 
        /// in the <see cref="System.Web.UI.WebControls.RadioButtonList"/>. Currently not being 
        /// used.</param>
        /// <param name="p">The parameters used for binding. Currently not being used.</param>
        public virtual void Bind(object control, object value, PropertyInfo pi, params object[] p)
        {
            if (value == null) return;

            RadioButtonList rbl = control as RadioButtonList;

            if (rbl == null) return;

            rbl.Items.Clear();

            var includeEmpty = !pi.IsNonEmpty();

            IEnumerable<ValueItem> list = PropertyHelper.GetCollectionWithDefault(value, includeEmpty);

            foreach (ValueItem item in list)
            {
                ListItem listitem = new ListItem(item.Text, item.Value.ToString()) {Selected = item.Selected};

                rbl.Items.Add(listitem);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Populates the specified <see cref="System.Web.UI.WebControls.DropDownList"/> with 
        /// the specified collection of values.
        /// </summary>
        /// <remarks>
        /// The supported types of items in the specified collection of values can be of type 
        /// Adf.Business.DomainObject, Adf.Core.Descriptor, System.Enum, SmartReference etc.
        /// </remarks>
        /// <param name="control">The <see cref="System.Web.UI.WebControls.DropDownList"/> 
        /// to bind to.</param>
        /// <param name="value">The collection of values to bind.</param>
        /// <param name="pi">The property used to check whether an empty item will be included in the 
        /// <see cref="System.Web.UI.WebControls.DropDownList"/>.</param>
        /// <param name="p">The parameters used for binding. Currently not being used.</param>
        public virtual void Bind(object control, object value, PropertyInfo pi, params object[] p)
        {
            if (value == null) return;

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

            ddl.Items.Clear();

            var items = BindManager.GetListFor(pi);

            if (p != null && p.Length > 0)
            {
                var typeResolver = p[0] as ObjectResolver;

                if (typeResolver != null)
                {
                    Func<IEnumerable> func;
                    if (typeResolver.TryGetValue(ddl.ID, out func))
                    {
                        items = func.Invoke();
                    }
                    else if (typeResolver.TryGetValue(value.GetType(), out func))
                    {
                        items = func.Invoke();
                    }
                }
            }

            var includeEmpty = !pi.IsNonEmpty();

            foreach (var item in PropertyHelper.GetCollectionWithDefault(pi.PropertyType, value, includeEmpty, items))
            {
                ddl.Items.Add(new ListItem(item.Text, item.Value.ToString()) {Selected = item.Selected});
            }

            if (ddl.SelectedValue.IsNullOrEmpty() && !PropertyHelper.IsEmpty(value)) ddl.Items.Insert(0, new ListItem("<invalid value>") { Selected = true });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Populates the specified <see cref="System.Web.UI.WebControls.RadioButtonList"/> with 
        /// the specified collection of values using the specified parameters.
        /// </summary>
        /// <remarks>
        /// The supported types of items in the specified collection of values can be of type 
        /// Adf.Business.DomainObject, Adf.Business.SmartReferences.SmartReference&lt;T&gt;, 
        /// Adf.Core.Descriptor, System.Enum etc.
        /// </remarks>
        /// <param name="control">The <see cref="System.Web.UI.WebControls.RadioButtonList"/> 
        /// to bind to.</param>
        /// <param name="value">The collection of values to bind.</param>
        /// <param name="pi">The property used to check whether an empty item will be included 
        /// in the <see cref="System.Web.UI.WebControls.RadioButtonList"/>. Currently not being 
        /// used.</param>
        /// <param name="p">The parameters used for binding. Currently not being used.</param>
        public virtual void Bind(object control, object value, PropertyInfo pi, params object[] p)
        {
            if (value == null) return;

            var rbl = control as RadioButtonList;

            if (rbl == null) return;

            rbl.Items.Clear();

            var items = BindManager.GetListFor(pi);

            if (p != null && p.Length > 0)
            {
                var typeResolver = p[0] as ObjectResolver;

                if (typeResolver != null)
                {
                    Func<IEnumerable> func;
                    if (typeResolver.TryGetValue(rbl.ID, out func))
                    {
                        items = func.Invoke();
                    }
                    else if (typeResolver.TryGetValue(value.GetType(), out func))
                    {
                        items = func.Invoke();
                    }
                }
            }

            var includeEmpty = !pi.IsNonEmpty();

            var list = PropertyHelper.GetCollectionWithDefault(pi.PropertyType, value, includeEmpty);

            foreach (var item in list)
            {
                var listitem = new ListItem(item.Text, item.Value.ToString()) {Selected = item.Selected};

                rbl.Items.Add(listitem);
            }
        }