예제 #1
0
 public bool Equals(DataKey other)
 {
     if (other == null)
     {
         return(false);
     }
     string[] array     = this._keyNames;
     string[] strArray2 = other._keyNames;
     if ((array == null) && (this._keyTable != null))
     {
         array = new string[this._keyTable.Count];
         this._keyTable.Keys.CopyTo(array, 0);
     }
     if ((strArray2 == null) && (this._keyTable != null))
     {
         strArray2 = new string[other._keyTable.Count];
         other._keyTable.Keys.CopyTo(strArray2, 0);
     }
     if (!DataBoundControlHelper.CompareStringArrays(array, strArray2))
     {
         return(false);
     }
     if ((array != null) && (strArray2 != null))
     {
         foreach (string str in array)
         {
             if (!object.Equals(this[str], other[str]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #2
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);
        }
        protected internal override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!DesignMode && !String.IsNullOrEmpty(ItemType))
            {
                DataBoundControlHelper.EnableDynamicData(this, ItemType);
            }
        }
예제 #4
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);
        }
예제 #5
0
 private bool ShouldGenerateField(Type propertyType, DetailsView detailsView)
 {
     if (detailsView.RenderingCompatibility < VersionUtil.Framework45 && AutoGenerateEnumFields == null)
     {
         //This is for backward compatibility. Before 4.5, auto generating fields used to call into this method
         //and if someone has overriden this method to force generation of columns, the scenario should still
         //work.
         return(detailsView.IsBindableType(propertyType));
     }
     else
     {
         //If AutoGenerateEnumFileds is null here, the rendering compatibility must be 4.5
         return(DataBoundControlHelper.IsBindableType(propertyType, enableEnums: AutoGenerateEnumFields ?? true));
     }
 }
예제 #6
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);
        }
예제 #7
0
        /// <devdoc>
        /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary.  Indicate includeReadOnly
        /// to have readonly fields' values inserted into the dictionary.
        /// </devdoc>
        public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
        {
            DataBoundControlHelper.ExtractValuesFromBindableControls(dictionary, cell);

            IBindableTemplate bindableTemplate = ItemTemplate as IBindableTemplate;

            if (((rowState & DataControlRowState.Alternate) != 0) && (AlternatingItemTemplate != null))
            {
                bindableTemplate = AlternatingItemTemplate as IBindableTemplate;
            }
            if (((rowState & DataControlRowState.Edit) != 0) && EditItemTemplate != null)
            {
                bindableTemplate = EditItemTemplate as IBindableTemplate;
            }
            else if ((rowState & DataControlRowState.Insert) != 0 && InsertVisible)
            {
                if (InsertItemTemplate != null)
                {
                    bindableTemplate = InsertItemTemplate as IBindableTemplate;
                }
                else
                {
                    if (EditItemTemplate != null)
                    {
                        bindableTemplate = EditItemTemplate as IBindableTemplate;
                    }
                }
            }

            if (bindableTemplate != null)
            {
                bool convertEmptyStringToNull = ConvertEmptyStringToNull;
                foreach (DictionaryEntry entry in bindableTemplate.ExtractValues(cell.BindingContainer))
                {
                    object value = entry.Value;
                    if (convertEmptyStringToNull && value is string && ((string)value).Length == 0)
                    {
                        dictionary[entry.Key] = null;
                    }
                    else
                    {
                        dictionary[entry.Key] = value;
                    }
                }
            }
            return;
        }
 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);
 }
예제 #9
0
        protected internal override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (Page != null)
            {
                Page.PreLoad += new EventHandler(this.OnPagePreLoad);
                if (!IsViewStateEnabled && Page.IsPostBack)
                {
                    RequiresDataBinding = true;
                }
            }

            if (!DesignMode && !String.IsNullOrEmpty(ItemType))
            {
                DataBoundControlHelper.EnableDynamicData(this, ItemType);
            }
        }
예제 #10
0
        public bool Equals(DataKey other)
        {
            if (other == null)
            {
                return(false);
            }

            string[] aKeys = _keyNames;
            string[] bKeys = other._keyNames;

            if (aKeys == null && _keyTable != null)
            {
                aKeys = new string[_keyTable.Count];
                _keyTable.Keys.CopyTo(aKeys, 0);
            }

            if (bKeys == null && _keyTable != null)
            {
                bKeys = new string[other._keyTable.Count];
                other._keyTable.Keys.CopyTo(bKeys, 0);
            }

            // Compare the keys array
            bool hasSameKeyNames = DataBoundControlHelper.CompareStringArrays(aKeys, bKeys);

            if (hasSameKeyNames)
            {
                if (aKeys != null && bKeys != null)
                {
                    foreach (string key in aKeys)
                    {
                        if (!Object.Equals(this[key], other[key]))
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }

            return(false);
        }
        public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
        {
            DataBoundControlHelper.ExtractValuesFromBindableControls(dictionary, cell);
            IBindableTemplate itemTemplate = this.ItemTemplate as IBindableTemplate;

            if (((rowState & DataControlRowState.Alternate) != DataControlRowState.Normal) && (this.AlternatingItemTemplate != null))
            {
                itemTemplate = this.AlternatingItemTemplate as IBindableTemplate;
            }
            if (((rowState & DataControlRowState.Edit) != DataControlRowState.Normal) && (this.EditItemTemplate != null))
            {
                itemTemplate = this.EditItemTemplate as IBindableTemplate;
            }
            else if (((rowState & DataControlRowState.Insert) != DataControlRowState.Normal) && this.InsertVisible)
            {
                if (this.InsertItemTemplate != null)
                {
                    itemTemplate = this.InsertItemTemplate as IBindableTemplate;
                }
                else if (this.EditItemTemplate != null)
                {
                    itemTemplate = this.EditItemTemplate as IBindableTemplate;
                }
            }
            if (itemTemplate != null)
            {
                bool convertEmptyStringToNull = this.ConvertEmptyStringToNull;
                foreach (DictionaryEntry entry in itemTemplate.ExtractValues(cell.BindingContainer))
                {
                    object obj2 = entry.Value;
                    if ((convertEmptyStringToNull && (obj2 is string)) && (((string)obj2).Length == 0))
                    {
                        dictionary[entry.Key] = null;
                    }
                    else
                    {
                        dictionary[entry.Key] = obj2;
                    }
                }
            }
        }
예제 #12
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);
            }
        }
예제 #13
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);
        }
예제 #15
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);
        }
예제 #16
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);
        }