Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / xsp / System / Web / UI / WebControls / BaseDataBoundControl.cs / 1 / BaseDataBoundControl.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Security.Permissions; using System.Web.Util; ////// A BaseDataBoundControl is bound to a data source and generates its /// user interface (or child control hierarchy typically), by enumerating /// the items in the data source it is bound to. /// BaseDataBoundControl is an abstract base class that defines the common /// characteristics of all controls that use a list as a data source, such as /// DataGrid, DataBoundTable, ListBox etc. It encapsulates the logic /// of how a data-bound control binds to collections or DataControl instances. /// [ Designer("System.Web.UI.Design.WebControls.BaseDataBoundControlDesigner, " + AssemblyRef.SystemDesign), DefaultProperty("DataSourceID") ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public abstract class BaseDataBoundControl : WebControl { private static readonly object EventDataBound = new object(); private object _dataSource; private bool _requiresDataBinding; private bool _inited; private bool _preRendered; private bool _requiresBindToNull; private bool _throwOnDataPropertyChange; ////// The data source to bind to. This allows a BaseDataBoundControl to bind /// to arbitrary lists of data items. /// [ Bindable(true), DefaultValue(null), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Themeable(false), WebCategory("Data"), WebSysDescription(SR.BaseDataBoundControl_DataSource), ] public virtual object DataSource { get { return _dataSource; } set { if (value != null) { ValidateDataSource(value); } _dataSource = value; OnDataPropertyChanged(); } } ////// The ID of the DataControl that this control should use to retrieve /// its data source. When the control is bound to a DataControl, it /// can retrieve a data source instance on-demand, and thereby attempt /// to work in auto-DataBind mode. /// [ DefaultValue(""), Themeable(false), WebCategory("Data"), WebSysDescription(SR.BaseDataBoundControl_DataSourceID) ] public virtual string DataSourceID { get { object o = ViewState["DataSourceID"]; if (o != null) { return (string)o; } return String.Empty; } set { if (String.IsNullOrEmpty(value) && !String.IsNullOrEmpty(DataSourceID)) { _requiresBindToNull = true; } ViewState["DataSourceID"] = value; OnDataPropertyChanged(); } } protected bool Initialized { get { return _inited; } } protected bool IsBoundUsingDataSourceID { get { return (DataSourceID.Length > 0); } } protected bool RequiresDataBinding { get { return _requiresDataBinding; } set { // if we have to play catch-up here because we've already PreRendered, call EnsureDataBound if (value && _preRendered && DataSourceID.Length > 0 && Page != null && !Page.IsCallback) { _requiresDataBinding = true; EnsureDataBound(); } else { _requiresDataBinding = value; } } } [ WebCategory("Data"), WebSysDescription(SR.BaseDataBoundControl_OnDataBound) ] public event EventHandler DataBound { add { Events.AddHandler(EventDataBound, value); } remove { Events.RemoveHandler(EventDataBound, value); } } protected void ConfirmInitState() { _inited = true; // do this in OnLoad in case we were added to the page after Page.OnPreLoad } ////// Overriden by BaseDataBoundControl to use its properties to determine the real /// data source that the control should bind to. It then clears the existing /// control hierarchy, and calls CreateChildControls to create a new control /// hierarchy based on the resolved data source. /// The implementation resolves various data source related properties to /// arrive at the appropriate IEnumerable implementation to use as the real /// data source. /// When resolving data sources, the DataSourceID takes highest precedence. /// If DataSourceID is not set, the value of the DataSource property is used. /// In this second alternative, DataMember is used to extract the appropriate /// list if the control has been handed an IListSource as a data source. /// /// Data bound controls should override PerformDataBinding instead /// of DataBind. If DataBind if overridden, the OnDataBinding and OnDataBound events will /// fire in the wrong order. However, for backwards compat on ListControl and AdRotator, we /// can't seal this method. It is sealed on all new BaseDataBoundControl-derived controls. /// public override void DataBind() { // Don't databind when the control is in the designer but not top-level if (DesignMode) { IDictionary designModeState = GetDesignModeState(); if (((designModeState == null) || (designModeState["EnableDesignTimeDataBinding"] == null)) && (Site == null)) { return; } } PerformSelect(); } protected virtual void EnsureDataBound() { try { _throwOnDataPropertyChange = true; if (RequiresDataBinding && (DataSourceID.Length > 0 || _requiresBindToNull)) { DataBind(); _requiresBindToNull = false; } } finally { _throwOnDataPropertyChange = false; } } protected virtual void OnDataBound(EventArgs e) { EventHandler handler = Events[EventDataBound] as EventHandler; if (handler != null) { handler(this, e); } } ////// This method is called when DataMember, DataSource, or DataSourceID is changed. /// protected virtual void OnDataPropertyChanged() { if (_throwOnDataPropertyChange) { throw new HttpException(SR.GetString(SR.DataBoundControl_InvalidDataPropertyChange, ID)); } if (_inited) { RequiresDataBinding = true; } } 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; } } } protected virtual void OnPagePreLoad(object sender, EventArgs e) { _inited = true; if (Page != null) { Page.PreLoad -= new EventHandler(this.OnPagePreLoad); } } protected internal override void OnPreRender(EventArgs e) { _preRendered = true; EnsureDataBound(); base.OnPreRender(e); } ////// Override to control how the data is selected and the control is databound. /// protected abstract void PerformSelect(); protected abstract void ValidateDataSource(object dataSource); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Security.Permissions; using System.Web.Util; ////// A BaseDataBoundControl is bound to a data source and generates its /// user interface (or child control hierarchy typically), by enumerating /// the items in the data source it is bound to. /// BaseDataBoundControl is an abstract base class that defines the common /// characteristics of all controls that use a list as a data source, such as /// DataGrid, DataBoundTable, ListBox etc. It encapsulates the logic /// of how a data-bound control binds to collections or DataControl instances. /// [ Designer("System.Web.UI.Design.WebControls.BaseDataBoundControlDesigner, " + AssemblyRef.SystemDesign), DefaultProperty("DataSourceID") ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public abstract class BaseDataBoundControl : WebControl { private static readonly object EventDataBound = new object(); private object _dataSource; private bool _requiresDataBinding; private bool _inited; private bool _preRendered; private bool _requiresBindToNull; private bool _throwOnDataPropertyChange; ////// The data source to bind to. This allows a BaseDataBoundControl to bind /// to arbitrary lists of data items. /// [ Bindable(true), DefaultValue(null), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Themeable(false), WebCategory("Data"), WebSysDescription(SR.BaseDataBoundControl_DataSource), ] public virtual object DataSource { get { return _dataSource; } set { if (value != null) { ValidateDataSource(value); } _dataSource = value; OnDataPropertyChanged(); } } ////// The ID of the DataControl that this control should use to retrieve /// its data source. When the control is bound to a DataControl, it /// can retrieve a data source instance on-demand, and thereby attempt /// to work in auto-DataBind mode. /// [ DefaultValue(""), Themeable(false), WebCategory("Data"), WebSysDescription(SR.BaseDataBoundControl_DataSourceID) ] public virtual string DataSourceID { get { object o = ViewState["DataSourceID"]; if (o != null) { return (string)o; } return String.Empty; } set { if (String.IsNullOrEmpty(value) && !String.IsNullOrEmpty(DataSourceID)) { _requiresBindToNull = true; } ViewState["DataSourceID"] = value; OnDataPropertyChanged(); } } protected bool Initialized { get { return _inited; } } protected bool IsBoundUsingDataSourceID { get { return (DataSourceID.Length > 0); } } protected bool RequiresDataBinding { get { return _requiresDataBinding; } set { // if we have to play catch-up here because we've already PreRendered, call EnsureDataBound if (value && _preRendered && DataSourceID.Length > 0 && Page != null && !Page.IsCallback) { _requiresDataBinding = true; EnsureDataBound(); } else { _requiresDataBinding = value; } } } [ WebCategory("Data"), WebSysDescription(SR.BaseDataBoundControl_OnDataBound) ] public event EventHandler DataBound { add { Events.AddHandler(EventDataBound, value); } remove { Events.RemoveHandler(EventDataBound, value); } } protected void ConfirmInitState() { _inited = true; // do this in OnLoad in case we were added to the page after Page.OnPreLoad } ////// Overriden by BaseDataBoundControl to use its properties to determine the real /// data source that the control should bind to. It then clears the existing /// control hierarchy, and calls CreateChildControls to create a new control /// hierarchy based on the resolved data source. /// The implementation resolves various data source related properties to /// arrive at the appropriate IEnumerable implementation to use as the real /// data source. /// When resolving data sources, the DataSourceID takes highest precedence. /// If DataSourceID is not set, the value of the DataSource property is used. /// In this second alternative, DataMember is used to extract the appropriate /// list if the control has been handed an IListSource as a data source. /// /// Data bound controls should override PerformDataBinding instead /// of DataBind. If DataBind if overridden, the OnDataBinding and OnDataBound events will /// fire in the wrong order. However, for backwards compat on ListControl and AdRotator, we /// can't seal this method. It is sealed on all new BaseDataBoundControl-derived controls. /// public override void DataBind() { // Don't databind when the control is in the designer but not top-level if (DesignMode) { IDictionary designModeState = GetDesignModeState(); if (((designModeState == null) || (designModeState["EnableDesignTimeDataBinding"] == null)) && (Site == null)) { return; } } PerformSelect(); } protected virtual void EnsureDataBound() { try { _throwOnDataPropertyChange = true; if (RequiresDataBinding && (DataSourceID.Length > 0 || _requiresBindToNull)) { DataBind(); _requiresBindToNull = false; } } finally { _throwOnDataPropertyChange = false; } } protected virtual void OnDataBound(EventArgs e) { EventHandler handler = Events[EventDataBound] as EventHandler; if (handler != null) { handler(this, e); } } ////// This method is called when DataMember, DataSource, or DataSourceID is changed. /// protected virtual void OnDataPropertyChanged() { if (_throwOnDataPropertyChange) { throw new HttpException(SR.GetString(SR.DataBoundControl_InvalidDataPropertyChange, ID)); } if (_inited) { RequiresDataBinding = true; } } 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; } } } protected virtual void OnPagePreLoad(object sender, EventArgs e) { _inited = true; if (Page != null) { Page.PreLoad -= new EventHandler(this.OnPagePreLoad); } } protected internal override void OnPreRender(EventArgs e) { _preRendered = true; EnsureDataBound(); base.OnPreRender(e); } ////// Override to control how the data is selected and the control is databound. /// protected abstract void PerformSelect(); protected abstract void ValidateDataSource(object dataSource); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListParagraph.cs
- NullReferenceException.cs
- hebrewshape.cs
- wgx_sdk_version.cs
- OperationInvokerTrace.cs
- MetadataArtifactLoaderComposite.cs
- XmlAttributeCache.cs
- ErrorFormatter.cs
- HostExecutionContextManager.cs
- CodeActivityMetadata.cs
- CalendarButtonAutomationPeer.cs
- StringDictionary.cs
- RestClientProxyHandler.cs
- DataTemplateKey.cs
- QilParameter.cs
- TextTreeInsertUndoUnit.cs
- CodeGeneratorAttribute.cs
- WmlValidationSummaryAdapter.cs
- LayoutDump.cs
- UriParserTemplates.cs
- DBSchemaTable.cs
- BuilderElements.cs
- RefreshEventArgs.cs
- ContextStaticAttribute.cs
- BaseTemplateCodeDomTreeGenerator.cs
- WpfKnownType.cs
- CapabilitiesState.cs
- PagerSettings.cs
- SByte.cs
- Vector3DCollection.cs
- PipelineModuleStepContainer.cs
- StateChangeEvent.cs
- Opcode.cs
- SourceChangedEventArgs.cs
- ToRequest.cs
- ListViewTableCell.cs
- ButtonColumn.cs
- VirtualizingPanel.cs
- SafeNativeMethods.cs
- TimelineCollection.cs
- _LocalDataStore.cs
- XmlnsCache.cs
- ScriptModule.cs
- MetadataPropertyAttribute.cs
- PropertyDescriptorGridEntry.cs
- TableRowCollection.cs
- PersistenceTypeAttribute.cs
- HyperLinkStyle.cs
- NativeMethods.cs
- X509CertificateValidator.cs
- WeakEventTable.cs
- AuthenticationModulesSection.cs
- DataGridViewSelectedColumnCollection.cs
- UnmanagedBitmapWrapper.cs
- sitestring.cs
- ImageIndexConverter.cs
- VisualBrush.cs
- ProxyWebPartConnectionCollection.cs
- LocatorBase.cs
- IgnoreFileBuildProvider.cs
- CompilerLocalReference.cs
- ClientConfigurationHost.cs
- DataTrigger.cs
- TreeNodeBinding.cs
- NetworkStream.cs
- DataTableNameHandler.cs
- StringToken.cs
- WorkflowItemsPresenter.cs
- Menu.cs
- IndependentAnimationStorage.cs
- BuilderPropertyEntry.cs
- ConvertTextFrag.cs
- ExpressionTextBoxAutomationPeer.cs
- WindowsFormsHost.cs
- AsyncDataRequest.cs
- xml.cs
- FileChangesMonitor.cs
- PrintingPermission.cs
- RecordsAffectedEventArgs.cs
- MiniCustomAttributeInfo.cs
- ProfilePropertySettings.cs
- PolyBezierSegment.cs
- CommandHelpers.cs
- WpfWebRequestHelper.cs
- CallbackDebugElement.cs
- SpellerError.cs
- SortExpressionBuilder.cs
- ContractTypeNameElement.cs
- IList.cs
- DesignerDataTableBase.cs
- ToolStripItemDesigner.cs
- AuthorizationRule.cs
- StrongNameIdentityPermission.cs
- SocketException.cs
- SingleStorage.cs
- StylusEditingBehavior.cs
- Asn1Utilities.cs
- ClonableStack.cs
- SerializationTrace.cs
- DragDrop.cs