Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / WebControls / DataBoundControlDesigner.cs / 1 / DataBoundControlDesigner.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design.WebControls { using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Data; using System.Design; using System.Diagnostics; using System.Drawing; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.Design.Util; using System.Web.UI.WebControls; using System.Windows.Forms; ////// /// DataBoundControlDesigner is the designer associated with a /// DataBoundControl. It provides the basic shared design-time experience /// for all data-bound controls. /// public class DataBoundControlDesigner : BaseDataBoundControlDesigner, IDataBindingSchemaProvider, IDataSourceProvider { private IDataSourceDesigner _dataSourceDesigner; ////// /// Adds designer actions to the ActionLists collection. /// public override DesignerActionListCollection ActionLists { get { DesignerActionListCollection actionLists = new DesignerActionListCollection(); if (UseDataSourcePickerActionList) { actionLists.Add(new DataBoundControlActionList(this, DataSourceDesigner)); } actionLists.AddRange(base.ActionLists); return actionLists; } } ////// /// Implements the designer's version of the DataMember property. /// This is used to shadow the DataMember property of the /// runtime control. /// public string DataMember { get { return ((DataBoundControl)Component).DataMember; } set { ((DataBoundControl)Component).DataMember = value; OnDataSourceChanged(true); } } ////// /// Provides access to the designer of the DataControl, when one /// is selected for data binding. /// public IDataSourceDesigner DataSourceDesigner { get { return _dataSourceDesigner; } } public DesignerDataSourceView DesignerView { get { // Get the current view based on the DataMember DesignerDataSourceView view = null; if (DataSourceDesigner != null) { view = DataSourceDesigner.GetView(DataMember); if (view == null && (String.IsNullOrEmpty(DataMember))) { // DataMember is not set, and view was not found, get the first view string[] viewNames = DataSourceDesigner.GetViewNames(); if (viewNames != null && viewNames.Length > 0) { view = DataSourceDesigner.GetView(viewNames[0]); } } } return view; } } ////// /// Used to determine the number of sample rows the control wishes to show. /// protected virtual int SampleRowCount { get { return 5; } } ////// /// Used to determine whether the control should render its default action lists, /// containing a DataSourceID dropdown and related tasks. /// protected virtual bool UseDataSourcePickerActionList { get { return true; } } ///protected override bool ConnectToDataSource() { IDataSourceDesigner designer = GetDataSourceDesigner(); if (_dataSourceDesigner != designer) { if (_dataSourceDesigner != null) { _dataSourceDesigner.DataSourceChanged -= new EventHandler(OnDataSourceChanged); _dataSourceDesigner.SchemaRefreshed -= new EventHandler(OnSchemaRefreshed); } _dataSourceDesigner = designer; if (_dataSourceDesigner != null) { _dataSourceDesigner.DataSourceChanged += new EventHandler(OnDataSourceChanged); _dataSourceDesigner.SchemaRefreshed += new EventHandler(OnSchemaRefreshed); } return true; } return false; } /// /// /// Calls the transacted change for creating a new datasource /// protected override void CreateDataSource() { InvokeTransactedChange(Component, new TransactedChangeCallback(CreateDataSourceCallback), null, SR.GetString(SR.BaseDataBoundControl_CreateDataSourceTransaction)); } ////// Transacted callback for creating a datasource /// private bool CreateDataSourceCallback(object context) { string newDataSourceID; DialogResult result = BaseDataBoundControlDesigner.ShowCreateDataSourceDialog(this, typeof(IDataSource), true, out newDataSourceID); if (newDataSourceID.Length > 0) { DataSourceID = newDataSourceID; } return (result == DialogResult.OK); } ///protected override void DataBind(BaseDataBoundControl dataBoundControl) { IEnumerable designTimeDataSource = GetDesignTimeDataSource(); string oldDataSourceID = dataBoundControl.DataSourceID; object oldDataSource = dataBoundControl.DataSource; dataBoundControl.DataSource = designTimeDataSource; dataBoundControl.DataSourceID = String.Empty; try { if (designTimeDataSource != null) { dataBoundControl.DataBind(); } } finally { dataBoundControl.DataSource = oldDataSource; dataBoundControl.DataSourceID = oldDataSourceID; } } /// protected override void DisconnectFromDataSource() { if (_dataSourceDesigner != null) { _dataSourceDesigner.DataSourceChanged -= new EventHandler(OnDataSourceChanged); _dataSourceDesigner.SchemaRefreshed -= new EventHandler(OnSchemaRefreshed); _dataSourceDesigner = null; } } /// protected override void Dispose(bool disposing) { if (disposing) { if (_dataSourceDesigner != null) { _dataSourceDesigner.DataSourceChanged -= new EventHandler(OnDataSourceChanged); _dataSourceDesigner.SchemaRefreshed -= new EventHandler(OnSchemaRefreshed); _dataSourceDesigner = null; } } base.Dispose(disposing); } private IDataSourceDesigner GetDataSourceDesigner() { IDataSourceDesigner designer = null; string dataSourceID = DataSourceID; if (!String.IsNullOrEmpty(dataSourceID)) { System.Web.UI.Control dataSourceControl = ControlHelper.FindControl(Component.Site, (System.Web.UI.Control)Component, dataSourceID); if (dataSourceControl != null && dataSourceControl.Site != null) { IDesignerHost designerHost = (IDesignerHost)dataSourceControl.Site.GetService(typeof(IDesignerHost)); if (designerHost != null) { designer = designerHost.GetDesigner(dataSourceControl) as IDataSourceDesigner; } } } return designer; } protected virtual IEnumerable GetDesignTimeDataSource() { bool isSampleData; // IEnumerable data = null; DesignerDataSourceView view = DesignerView; if (view != null) { // Use IDataSourceDesigner interface if available try { data = view.GetDesignTimeData(SampleRowCount, out isSampleData); } catch (Exception ex) { if (Component.Site != null) { IComponentDesignerDebugService debugService = (IComponentDesignerDebugService)Component.Site.GetService(typeof(IComponentDesignerDebugService)); if (debugService != null) { debugService.Fail(SR.GetString(SR.DataSource_DebugService_FailedCall, "DesignerDataSourceView.GetDesignTimeData", ex.Message)); } } } } else { // Use IDataSourceProvider interface if available IEnumerable selectedDataSource = ((IDataSourceProvider)this).GetResolvedSelectedDataSource(); if (selectedDataSource != null) { DataTable dataTable = DesignTimeData.CreateSampleDataTable(selectedDataSource); data = DesignTimeData.GetDesignTimeDataSource(dataTable, SampleRowCount); isSampleData = true; } } if (data != null) { ICollection collectionData = data as ICollection; if ((collectionData == null) || (collectionData.Count > 0)) { return data; } } // No design time data is available from the data source, create our own sample data isSampleData = true; return GetSampleDataSource(); } protected virtual IEnumerable GetSampleDataSource() { // DataTable dummyDataTable = null; if (((DataBoundControl)Component).DataSourceID.Length > 0) { dummyDataTable = DesignTimeData.CreateDummyDataBoundDataTable(); } else { dummyDataTable = DesignTimeData.CreateDummyDataTable(); } IEnumerable liveDataSource = DesignTimeData.GetDesignTimeDataSource(dummyDataTable, SampleRowCount); return liveDataSource; } private void OnDataSourceChanged(object sender, EventArgs e) { OnDataSourceChanged(true); } private void OnSchemaRefreshed(object sender, EventArgs e) { OnSchemaRefreshed(); } /// /// /// Overridden by the designer to shadow various runtime properties /// with corresponding properties that it implements. /// /// /// The properties to be filtered. /// protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); PropertyDescriptor prop; prop = (PropertyDescriptor)properties["DataMember"]; Debug.Assert(prop != null); prop = TypeDescriptor.CreateProperty(this.GetType(), prop, new Attribute[] { new TypeConverterAttribute(typeof(DataMemberConverter)) }); properties["DataMember"] = prop; prop = (PropertyDescriptor)properties["DataSource"]; Debug.Assert(prop != null); prop = TypeDescriptor.CreateProperty(this.GetType(), prop, new Attribute[] { new TypeConverterAttribute(typeof(DataSourceConverter)) }); properties["DataSource"] = prop; prop = (PropertyDescriptor)properties["DataSourceID"]; Debug.Assert(prop != null); prop = TypeDescriptor.CreateProperty(this.GetType(), prop, new Attribute[] { new TypeConverterAttribute(typeof(DataSourceIDConverter)) }); properties["DataSourceID"] = prop; } #region Implementation of IDataSourceProvider ////// /// Returns the selected datasource. /// IEnumerable IDataSourceProvider.GetResolvedSelectedDataSource() { IEnumerable selectedDataSource = null; DataBinding binding = DataBindings["DataSource"]; if (binding != null) { selectedDataSource = DesignTimeData.GetSelectedDataSource(((DataBoundControl)Component), binding.Expression, DataMember); } return selectedDataSource; } ////// /// Returns the selected datasource. /// object IDataSourceProvider.GetSelectedDataSource() { object selectedDataSource = null; DataBinding binding = DataBindings["DataSource"]; if (binding != null) { selectedDataSource = DesignTimeData.GetSelectedDataSource(((DataBoundControl)Component), binding.Expression); } return selectedDataSource; } #endregion #region Implementation of IDataBindingSchemaProvider bool IDataBindingSchemaProvider.CanRefreshSchema { get { IDataSourceDesigner dataSourceDesigner = DataSourceDesigner; if (dataSourceDesigner != null) { return dataSourceDesigner.CanRefreshSchema; } return false; } } IDataSourceViewSchema IDataBindingSchemaProvider.Schema { get { DesignerDataSourceView designerView = DesignerView; if (designerView != null) { return designerView.Schema; } return null; } } void IDataBindingSchemaProvider.RefreshSchema(bool preferSilent) { IDataSourceDesigner dataSourceDesigner = DataSourceDesigner; if (dataSourceDesigner != null) { dataSourceDesigner.RefreshSchema(preferSilent); } } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LongCountAggregationOperator.cs
- SafeLocalMemHandle.cs
- ControlParameter.cs
- PreservationFileReader.cs
- IPAddress.cs
- ValidateNames.cs
- CollectionBase.cs
- StyleXamlParser.cs
- CharStorage.cs
- WebPartDisplayMode.cs
- GuidelineSet.cs
- InternalTransaction.cs
- DoubleKeyFrameCollection.cs
- FaultDesigner.cs
- TripleDESCryptoServiceProvider.cs
- SqlDataReader.cs
- TabControl.cs
- OverflowException.cs
- DLinqTableProvider.cs
- DynamicRendererThreadManager.cs
- Table.cs
- ImportDesigner.xaml.cs
- CompModHelpers.cs
- ProgressPage.cs
- TreeIterators.cs
- DynamicEndpointElement.cs
- GeometryDrawing.cs
- Border.cs
- TransformGroup.cs
- OleDbTransaction.cs
- MembershipSection.cs
- ServiceOperation.cs
- WebHttpBehavior.cs
- ResourceContainer.cs
- SrgsElementFactory.cs
- OperationCanceledException.cs
- TargetInvocationException.cs
- DrawingImage.cs
- __ConsoleStream.cs
- DataGridCellItemAutomationPeer.cs
- RegexCode.cs
- EventLogReader.cs
- DropSource.cs
- Pipe.cs
- UnsafeCollabNativeMethods.cs
- GeometryDrawing.cs
- KnownBoxes.cs
- ConfigXmlText.cs
- RtfNavigator.cs
- BoolExpr.cs
- SqlCharStream.cs
- ResourcePermissionBaseEntry.cs
- Latin1Encoding.cs
- HyperlinkAutomationPeer.cs
- EntityProviderFactory.cs
- XmlStreamNodeWriter.cs
- GridProviderWrapper.cs
- HierarchicalDataBoundControlAdapter.cs
- DependencyPropertyAttribute.cs
- ClientConfigurationHost.cs
- DataControlImageButton.cs
- DesignerCategoryAttribute.cs
- XmlToDatasetMap.cs
- Rectangle.cs
- DataFormats.cs
- WebControl.cs
- SerialErrors.cs
- GridPatternIdentifiers.cs
- XmlSchemaException.cs
- ClientRuntimeConfig.cs
- MatrixIndependentAnimationStorage.cs
- OneWayChannelListener.cs
- BindingManagerDataErrorEventArgs.cs
- RegexStringValidator.cs
- DataControlImageButton.cs
- WindowsFormsHostPropertyMap.cs
- UnhandledExceptionEventArgs.cs
- StdValidatorsAndConverters.cs
- LocalizationComments.cs
- XPathBinder.cs
- XmlTextReader.cs
- ClientSideQueueItem.cs
- EntityCommandDefinition.cs
- controlskin.cs
- WebPartEditorOkVerb.cs
- UserNameSecurityTokenProvider.cs
- _RequestCacheProtocol.cs
- SqlConnectionHelper.cs
- ContainerUIElement3D.cs
- WebPartZoneCollection.cs
- ReferenceEqualityComparer.cs
- OleDbPropertySetGuid.cs
- OutputChannel.cs
- SolidColorBrush.cs
- xmlfixedPageInfo.cs
- LinqDataSourceContextData.cs
- ValueUnavailableException.cs
- MenuItemCollectionEditorDialog.cs
- ExtensionSimplifierMarkupObject.cs
- RoutedEventValueSerializer.cs