コード例 #1
0
            /// <summary>
            /// Gets the list of data from the associated <see cref="IListDataSource"/> control and
            /// applies the specified filter and sort expression.
            /// </summary>
            /// <param name="arguments">A System.Web.UI.DataSourceSelectArguments that
            /// is used to request operations on the data beyond basic data retrieval.</param>
            /// <returns>An System.Collections.IEnumerable list of data from the associated EntityDataSource.</returns>
            protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
            {
                IListDataSource dataSource = _owner.GetListDataSource();
                IEnumerable     entityList = null;

                if (dataSource != null)
                {
                    entityList = dataSource.GetEntityList();
                }
                else
                {
                    _owner.DataBind();

                    if (_owner.DataSource is IEnumerable)
                    {
                        entityList = _owner.DataSource as IEnumerable;
                    }
                }

                if (entityList != null)
                {
                    // apply filter
                    OnApplyFilter(entityList);

                    if (!String.IsNullOrEmpty(Filter))
                    {
                        EntityUtil.SetPropertyValue(entityList, "Filter", Filter);
                    }

                    // apply sort
                    OnApplySort(entityList);

                    if (!String.IsNullOrEmpty(Sort))
                    {
                        EntityUtil.InvokeMethod(entityList, "Sort", new Object[] { Sort });
                    }
                }

                return(entityList);
            }
コード例 #2
0
        /// <summary>
        /// Updates and returns the value of the DataParameter object.
        /// </summary>
        /// <param name="context">The current System.Web.HttpContext of the request.</param>
        /// <param name="control">The System.Web.UI.Control that the parameter is bound to.</param>
        /// <returns>A System.Object that represents the updated and current value of the parameter.</returns>
        protected override Object Evaluate(HttpContext context, Control control)
        {
            String value = String.Empty;

            if (_dataSource == null && control != null)
            {
                _dataSource = control.FindControl(DataSourceID) as IListDataSource;
            }
            if (_dataSource != null)
            {
                IEnumerable entityList = _dataSource.GetEntityList();

                if (entityList != null)
                {
                    CommaDelimitedStringCollection values = new CommaDelimitedStringCollection();
                    String propertyName = PropertyName ?? EntityKeyName;
                    IList  list         = EntityUtil.GetEntityList(entityList);
                    Object temp;

                    foreach (Object item in list)
                    {
                        temp = EntityUtil.GetPropertyValue(item, EntityKeyName);

                        if (temp != null)
                        {
                            values.Add(String.Format("'{0}'", temp));
                        }
                    }

                    if (values.Count > 0)
                    {
                        value = String.Format("{0} IN ({1})", propertyName, values.ToString());
                    }
                }
            }

            return(value);
        }