Exemplo n.º 1
0
        protected virtual IEnumerable GetData()
        {
            if (DataSource != null && IsBoundUsingDataSourceID)
            {
                throw new HttpException("Control bound using both DataSourceID and DataSource properties.");
            }

            if (DataSource != null)
            {
                return(DataSourceResolver.ResolveDataSource(DataSource, DataMember));
            }

            if (!IsBoundUsingDataSourceID)
            {
                return(null);
            }

            IEnumerable result = null;

            DataSourceView boundDataSourceView = ConnectToDataSource();

            boundDataSourceView.Select(DataSourceSelectArguments.Empty, delegate(IEnumerable data) { result = data; });

            return(result);
        }
Exemplo n.º 2
0
        IEnumerable GetData()
        {
            IEnumerable result;

#if NET_2_0
            if (IsBoundUsingDataSourceID)
            {
                if (DataSourceID.Length == 0)
                {
                    return(null);
                }

                if (boundDataSource == null)
                {
                    return(null);
                }

                DataSourceView dsv = boundDataSource.GetView(String.Empty);
                dsv.Select(SelectArguments, new DataSourceViewSelectCallback(SelectCallback));

                result = data;
                data   = null;
            }
            else
#endif
            result = DataSourceResolver.ResolveDataSource(DataSource, DataMember);

            return(result);
        }
Exemplo n.º 3
0
        protected virtual IDataSource GetDataSource()
        {
            if (IsBoundUsingDataSourceID)
            {
                Control ctrl = FindDataSource();

                if (ctrl == null)
                {
                    throw new HttpException(string.Format("A control with ID '{0}' could not be found.", DataSourceID));
                }
                if (!(ctrl is IDataSource))
                {
                    throw new HttpException(string.Format("The control with ID '{0}' is not a control of type IDataSource.", DataSourceID));
                }
                return((IDataSource)ctrl);
            }

            IDataSource ds = DataSource as IDataSource;

            if (ds != null)
            {
                return(ds);
            }

            IEnumerable ie = DataSourceResolver.ResolveDataSource(DataSource, DataMember);

            return(new CollectionDataSource(ie));
        }
Exemplo n.º 4
0
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
#if !NET_2_0
            IEnumerable list = DataSourceResolver.ResolveDataSource(DataSource, DataMember);
            PerformDataBinding(list);
#else
            IEnumerable list = GetData().ExecuteSelect(DataSourceSelectArguments.Empty);
            InternalPerformDataBinding(list);
#endif
        }
Exemplo n.º 5
0
        protected override void CreateControlHierarchy(bool useDataSource)
        {
            Controls.Clear();
            ItemList.Clear();

            IEnumerable ds   = null;
            ArrayList   keys = null;

            if (useDataSource)
            {
                idx = 0;
                if (IsBoundUsingDataSourceID)
                {
                    ds = GetData();
                }
                else
                {
                    ds = DataSourceResolver.ResolveDataSource(DataSource, DataMember);
                }
                keys = DataKeysArray;
                keys.Clear();
            }
            else
            {
                idx = (int)ViewState ["Items"];
            }

            if ((ds == null) && (idx == 0))
            {
                return;
            }

            if (headerTemplate != null)
            {
                DoItem(-1, ListItemType.Header, null, useDataSource);
            }

            // items
            int          selected_index  = SelectedIndex;
            int          edit_item_index = EditItemIndex;
            ListItemType type;

            if (ds != null)
            {
                string key = DataKeyField;
                foreach (object o in ds)
                {
                    if (useDataSource && !String.IsNullOrEmpty(key))
                    {
                        keys.Add(DataBinder.GetPropertyValue(o, key));
                    }
                    type = ListItemType.Item;
                    if (idx == edit_item_index)
                    {
                        type = ListItemType.EditItem;
                    }
                    else if (idx == selected_index)
                    {
                        type = ListItemType.SelectedItem;
                    }
                    else if ((idx & 1) != 0)
                    {
                        type = ListItemType.AlternatingItem;
                    }

                    DoItemInLoop(idx, o, useDataSource, type);
                    idx++;
                }
            }
            else
            {
                for (int i = 0; i < idx; i++)
                {
                    type = ListItemType.Item;
                    if (i == edit_item_index)
                    {
                        type = ListItemType.EditItem;
                    }
                    else if (i == selected_index)
                    {
                        type = ListItemType.SelectedItem;
                    }
                    else if ((i & 1) != 0)
                    {
                        type = ListItemType.AlternatingItem;
                    }

                    DoItemInLoop(i, null, useDataSource, type);
                }
            }

            if (footerTemplate != null)
            {
                DoItem(-1, ListItemType.Footer, null, useDataSource);
            }

            ViewState ["Items"] = idx;
        }
Exemplo n.º 6
0
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);

            /* Make sure Items has been initialised */
            ListItemCollection listitems = Items;

            listitems.Clear();

            IEnumerable list;

#if NET_2_0
            list = GetData();
#else
            list = DataSourceResolver.ResolveDataSource(DataSource, DataMember);
#endif

            if (list == null)
            {
                return;
            }

            foreach (object container in list)
            {
                string text  = null;
                string value = null;

                if (DataTextField == String.Empty &&
                    DataValueField == String.Empty)
                {
                    text  = container.ToString();
                    value = text;
                }
                else
                {
                    if (DataTextField != String.Empty)
                    {
                        text = DataBinder.Eval(container, DataTextField).ToString();
                    }

                    if (DataValueField != String.Empty)
                    {
                        value = DataBinder.Eval(container, DataValueField).ToString();
                    }
                    else
                    {
                        value = text;
                    }

                    if (text == null &&
                        value != null)
                    {
                        text = value;
                    }
                }

                if (text == null)
                {
                    text = String.Empty;
                }
                if (value == null)
                {
                    value = String.Empty;
                }

                ListItem item = new ListItem(text, value);
                listitems.Add(item);
            }
#if NET_2_0
            RequiresDataBinding = false;
            IsDataBound         = true;
#endif
        }