Ejemplo n.º 1
0
        /// <devdoc>
        /// Gets the IHierarchicalDataSource that this control is bound to, if any.
        /// </devdoc>
        protected virtual IHierarchicalDataSource GetDataSource()
        {
            if (!DesignMode && _currentDataSourceValid && (_currentHierarchicalDataSource != null))
            {
                return(_currentHierarchicalDataSource);
            }

            IHierarchicalDataSource ds = null;
            string dataSourceID        = DataSourceID;

            if (dataSourceID.Length != 0)
            {
                // Try to find a DataSource control with the ID specified in DataSourceID
                Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
                if (control == null)
                {
                    throw new HttpException(SR.GetString(SR.HierarchicalDataControl_DataSourceDoesntExist, ID, dataSourceID));
                }
                ds = control as IHierarchicalDataSource;
                if (ds == null)
                {
                    throw new HttpException(SR.GetString(SR.HierarchicalDataControl_DataSourceIDMustBeHierarchicalDataControl, ID, dataSourceID));
                }
            }
            return(ds);
        }
Ejemplo n.º 2
0
        /// <devdoc>
        /// Returns the updated value of the parameter.
        /// </devdoc>
        protected internal override object Evaluate(HttpContext context, Control control)
        {
            if (control == null)
            {
                return(null);
            }

            string controlID    = ControlID;
            string propertyName = PropertyName;

            if (controlID.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.ControlParameter_ControlIDNotSpecified, Name));
            }

            Control foundControl = DataBoundControlHelper.FindControl(control, controlID);

            if (foundControl == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.ControlParameter_CouldNotFindControl, controlID, Name));
            }

            ControlValuePropertyAttribute controlValueProp = (ControlValuePropertyAttribute)TypeDescriptor.GetAttributes(foundControl)[typeof(ControlValuePropertyAttribute)];

            // If no property name is specified, use the ControlValuePropertyAttribute to determine which property to use.
            if (propertyName.Length == 0)
            {
                if ((controlValueProp != null) && (!String.IsNullOrEmpty(controlValueProp.Name)))
                {
                    propertyName = controlValueProp.Name;
                }
                else
                {
                    throw new InvalidOperationException(SR.GetString(SR.ControlParameter_PropertyNameNotSpecified, controlID, Name));
                }
            }

            // Get the value of the property
            object value = DataBinder.Eval(foundControl, propertyName);

            // Convert the value to null if this is the default property and the value is the property's default value
            if (controlValueProp != null &&
                String.Equals(controlValueProp.Name, propertyName, StringComparison.OrdinalIgnoreCase) &&
                controlValueProp.DefaultValue != null &&
                controlValueProp.DefaultValue.Equals(value))
            {
                return(null);
            }
            return(value);
        }
Ejemplo n.º 3
0
        /// <devdoc>
        /// Gets the IDataSource that this control is bound to, if any.
        /// Because this method can be called directly by derived classes, it's virtual so data can be retrieved
        /// from data sources that don't live on the page.
        /// </devdoc>
        protected virtual IDataSource GetDataSource()
        {
            if (!DesignMode && IsUsingModelBinders)
            {
                //Let the developer choose a custom ModelDataSource.
                CreatingModelDataSourceEventArgs e = new CreatingModelDataSourceEventArgs();
                OnCreatingModelDataSource(e);
                if (e.ModelDataSource != null)
                {
                    ModelDataSource = e.ModelDataSource;
                }

                //Update the properties of ModelDataSource so that it's ready for data-binding.
                UpdateModelDataSourceProperties(ModelDataSource);

                CallingDataMethodsEventHandler handler = Events[EventCallingDataMethods] as CallingDataMethodsEventHandler;
                if (handler != null)
                {
                    ModelDataSource.CallingDataMethods += handler;
                }

                return(ModelDataSource);
            }

            if (!DesignMode && _currentDataSourceValid && (_currentDataSource != null))
            {
                return(_currentDataSource);
            }

            IDataSource ds           = null;
            string      dataSourceID = DataSourceID;

            if (dataSourceID.Length != 0)
            {
                // Try to find a DataSource control with the ID specified in DataSourceID
                Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
                if (control == null)
                {
                    throw new HttpException(SR.GetString(SR.DataControl_DataSourceDoesntExist, ID, dataSourceID));
                }
                ds = control as IDataSource;
                if (ds == null)
                {
                    throw new HttpException(SR.GetString(SR.DataControl_DataSourceIDMustBeDataControl, ID, dataSourceID));
                }
            }
            return(ds);
        }
 private DataSourceView ConnectToDataSourceView()
 {
     if (!this._currentViewValid || base.DesignMode)
     {
         if ((this._currentView != null) && this._currentViewIsFromDataSourceID)
         {
             this._currentView.DataSourceViewChanged -= new EventHandler(this.OnDataSourceViewChanged);
         }
         IDataSource source       = null;
         string      dataSourceID = this.DataSourceID;
         if (dataSourceID.Length != 0)
         {
             Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
             if (control == null)
             {
                 throw new HttpException(System.Web.SR.GetString("DataControl_DataSourceDoesntExist", new object[] { this.ID, dataSourceID }));
             }
             source = control as IDataSource;
             if (source == null)
             {
                 throw new HttpException(System.Web.SR.GetString("DataControl_DataSourceIDMustBeDataControl", new object[] { this.ID, dataSourceID }));
             }
         }
         if (source == null)
         {
             source = new ReadOnlyDataSource(this.DataSource, this.DataMember);
         }
         else if (this.DataSource != null)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("DataControl_MultipleDataSources", new object[] { this.ID }));
         }
         DataSourceView view = source.GetView(this.DataMember);
         if (view == null)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("DataControl_ViewNotFound", new object[] { this.ID }));
         }
         this._currentViewIsFromDataSourceID = this.IsBoundUsingDataSourceID;
         this._currentView = view;
         if ((this._currentView != null) && this._currentViewIsFromDataSourceID)
         {
             this._currentView.DataSourceViewChanged += new EventHandler(this.OnDataSourceViewChanged);
         }
         this._currentViewValid = true;
     }
     return(this._currentView);
 }
Ejemplo n.º 5
0
        protected virtual IPageableItemContainer FindPageableItemContainer()
        {
            // the PagedControlID can be specified for finding a control within the same naming container
            // when the pager control isn't inside the IPageableItemContainter.
            if (!String.IsNullOrEmpty(PagedControlID))
            {
                // The IPageableItemContainer is found by FindControl if specified.
                Control control = DataBoundControlHelper.FindControl(this, PagedControlID);
                if (control == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.DataPager_PageableItemContainerNotFound, PagedControlID));
                }
                IPageableItemContainer container = control as IPageableItemContainer;
                if (container == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.DataPager_ControlIsntPageable, PagedControlID));
                }
                return(container);
            }
            else
            {
                // Look to see if parent container is IPageableItemContainer
                Control currentContainer = this.NamingContainer;
                IPageableItemContainer foundContainer = null;

                while (foundContainer == null && currentContainer != this.Page)
                {
                    if (currentContainer == null)
                    {
                        throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.DataPager_NoNamingContainer, ID));
                    }
                    foundContainer   = currentContainer as IPageableItemContainer;
                    currentContainer = currentContainer.NamingContainer;
                }

                return(foundContainer);
            }
        }
Ejemplo n.º 6
0
        protected internal override object Evaluate(HttpContext context, Control control)
        {
            if (control == null)
            {
                return(null);
            }
            string controlID    = this.ControlID;
            string propertyName = this.PropertyName;

            if (controlID.Length == 0)
            {
                throw new ArgumentException(System.Web.SR.GetString("ControlParameter_ControlIDNotSpecified", new object[] { base.Name }));
            }
            Control component = DataBoundControlHelper.FindControl(control, controlID);

            if (component == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("ControlParameter_CouldNotFindControl", new object[] { controlID, base.Name }));
            }
            ControlValuePropertyAttribute attribute = (ControlValuePropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ControlValuePropertyAttribute)];

            if (propertyName.Length == 0)
            {
                if ((attribute == null) || string.IsNullOrEmpty(attribute.Name))
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("ControlParameter_PropertyNameNotSpecified", new object[] { controlID, base.Name }));
                }
                propertyName = attribute.Name;
            }
            object obj2 = DataBinder.Eval(component, propertyName);

            if (((attribute != null) && string.Equals(attribute.Name, propertyName, StringComparison.OrdinalIgnoreCase)) && ((attribute.DefaultValue != null) && attribute.DefaultValue.Equals(obj2)))
            {
                return(null);
            }
            return(obj2);
        }
        protected virtual IDataSource GetDataSource()
        {
            if ((!base.DesignMode && this._currentDataSourceValid) && (this._currentDataSource != null))
            {
                return(this._currentDataSource);
            }
            IDataSource source       = null;
            string      dataSourceID = this.DataSourceID;

            if (dataSourceID.Length != 0)
            {
                Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
                if (control == null)
                {
                    throw new HttpException(System.Web.SR.GetString("DataControl_DataSourceDoesntExist", new object[] { this.ID, dataSourceID }));
                }
                source = control as IDataSource;
                if (source == null)
                {
                    throw new HttpException(System.Web.SR.GetString("DataControl_DataSourceIDMustBeDataControl", new object[] { this.ID, dataSourceID }));
                }
            }
            return(source);
        }
Ejemplo n.º 8
0
        /// <devdoc>
        /// Connects this data bound control to the appropriate DataSourceView
        /// and hooks up the appropriate event listener for the
        /// DataSourceViewChanged event. The return value is the new view (if
        /// any) that was connected to. An exception is thrown if there is
        /// a problem finding the requested view or data source.
        /// </devdoc>
        private DataSourceView ConnectToDataSourceView()
        {
            if (_currentViewValid && !DesignMode)
            {
                // If the current view is correct, there is no need to reconnect
                return(_currentView);
            }

            // Disconnect from old view, if necessary
            if ((_currentView != null) && (_currentViewIsFromDataSourceID))
            {
                // We only care about this event if we are bound through the DataSourceID property
                _currentView.DataSourceViewChanged -= new EventHandler(OnDataSourceViewChanged);
            }

            // Connect to new view
            IDataSource ds = null;

            if (!DesignMode && IsUsingModelBinders)
            {
                if (DataSourceID.Length != 0 || DataSource != null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.DataControl_ItemType_MultipleDataSources, ID));
                }
                //Let the developer choose a custom ModelDataSource.
                CreatingModelDataSourceEventArgs e = new CreatingModelDataSourceEventArgs();
                OnCreatingModelDataSource(e);
                if (e.ModelDataSource != null)
                {
                    ModelDataSource = e.ModelDataSource;
                }

                //Update the properties of ModelDataSource so that it's ready for data-binding.
                UpdateModelDataSourceProperties(ModelDataSource);

                //Add the CallingDataMethodsEvent
                CallingDataMethodsEventHandler handler = Events[EventCallingDataMethods] as CallingDataMethodsEventHandler;
                if (handler != null)
                {
                    ModelDataSource.CallingDataMethods += handler;
                }

                ds = ModelDataSource;
            }
            else
            {
                string dataSourceID = DataSourceID;

                if (dataSourceID.Length != 0)
                {
                    // Try to find a DataSource control with the ID specified in DataSourceID
                    Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
                    if (control == null)
                    {
                        throw new HttpException(SR.GetString(SR.DataControl_DataSourceDoesntExist, ID, dataSourceID));
                    }
                    ds = control as IDataSource;
                    if (ds == null)
                    {
                        throw new HttpException(SR.GetString(SR.DataControl_DataSourceIDMustBeDataControl, ID, dataSourceID));
                    }
                }
            }

            if (ds == null)
            {
                // DataSource control was not found, construct a temporary data source to wrap the data
                ds = new ReadOnlyDataSource(DataSource, DataMember);
            }
            else
            {
                // Ensure that both DataSourceID as well as DataSource are not set at the same time
                if (DataSource != null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.DataControl_MultipleDataSources, ID));
                }
            }

            // IDataSource was found, extract the appropriate view and return it
            DataSourceView newView = ds.GetView(DataMember);

            if (newView == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.DataControl_ViewNotFound, ID));
            }

            _currentViewIsFromDataSourceID = IsDataBindingAutomatic;
            _currentView = newView;
            if ((_currentView != null) && (_currentViewIsFromDataSourceID))
            {
                // We only care about this event if we are bound through the DataSourceID property
                _currentView.DataSourceViewChanged += new EventHandler(OnDataSourceViewChanged);
            }
            _currentViewValid = true;

            return(_currentView);
        }
Ejemplo n.º 9
0
        /// <devdoc>
        /// Connects this data bound control to the appropriate DataSourceView
        /// and hooks up the appropriate event listener for the
        /// DataSourceViewChanged event. The return value is the new view (if
        /// any) that was connected to. An exception is thrown if there is
        /// a problem finding the requested view or data source.
        /// </devdoc>
        private DataSourceView ConnectToDataSourceView()
        {
            if (_currentViewValid && !DesignMode)
            {
                // If the current view is correct, there is no need to reconnect
                return(_currentView);
            }

            // Disconnect from old view, if necessary
            if ((_currentView != null) && (_currentViewIsFromDataSourceID))
            {
                // We only care about this event if we are bound through the DataSourceID property
                _currentView.DataSourceViewChanged -= new EventHandler(OnDataSourceViewChanged);
            }

            // Connect to new view
            IDataSource ds           = null;
            string      dataSourceID = DataSourceID;

            if (dataSourceID.Length != 0)
            {
                // Try to find a DataSource control with the ID specified in DataSourceID
                Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
                if (control == null)
                {
                    throw new HttpException(SR.GetString(SR.DataControl_DataSourceDoesntExist, ID, dataSourceID));
                }
                ds = control as IDataSource;
                if (ds == null)
                {
                    throw new HttpException(SR.GetString(SR.DataControl_DataSourceIDMustBeDataControl, ID, dataSourceID));
                }
            }

            if (ds == null)
            {
                // DataSource control was not found, construct a temporary data source to wrap the data
                ds = new ReadOnlyDataSource(DataSource, DataMember);
            }
            else
            {
                // Ensure that both DataSourceID as well as DataSource are not set at the same time
                if (DataSource != null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.DataControl_MultipleDataSources, ID));
                }
            }

            // IDataSource was found, extract the appropriate view and return it
            DataSourceView newView = ds.GetView(DataMember);

            if (newView == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.DataControl_ViewNotFound, ID));
            }

            _currentViewIsFromDataSourceID = IsBoundUsingDataSourceID;
            _currentView = newView;
            if ((_currentView != null) && (_currentViewIsFromDataSourceID))
            {
                // We only care about this event if we are bound through the DataSourceID property
                _currentView.DataSourceViewChanged += new EventHandler(OnDataSourceViewChanged);
            }
            _currentViewValid = true;

            return(_currentView);
        }