Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / Util / DataControlHelper.cs / 1305376 / DataControlHelper.cs
namespace System.Web.DynamicData.Util { using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Resources; using System.Globalization; #if !ORYX_VNEXT using IDataBoundControlInterface = System.Web.UI.WebControls.IDataBoundControl; #else using IDataBoundControlInterface = System.Web.DynamicData.Util.IDataBoundControl; #endif internal static class DataControlHelper { internal static IDynamicDataSource FindDataSourceControl(Control current) { for (; ; current = current.NamingContainer) { // Don't look further than the Page, or if the control is not added to a page hierarchy if (current == null || current is Page) return null; IDataBoundControlInterface dataBoundControl = GetDataBoundControl(current, false /*failIfNotFound*/); // Not a data control: continue searching if (dataBoundControl == null) { continue; } // Return its DynamicDataSource return dataBoundControl.DataSourceObject as IDynamicDataSource; } } internal static IDataBoundControlInterface GetDataBoundControl(Control control, bool failIfNotFound) { if (control is IDataBoundControlInterface) { return (IDataBoundControlInterface)control; } #if ORYX_VNEXT IDataBoundControlInterface dataBoundControl = GetControlAdapter(control); #else IDataBoundControlInterface dataBoundControl = null; if (control is Repeater) { dataBoundControl = GetControlAdapter(control); } #endif if (dataBoundControl == null && failIfNotFound) { throw new Exception(String.Format( CultureInfo.CurrentCulture, DynamicDataResources.DynamicDataManager_UnsupportedControl, control.GetType())); } return dataBoundControl; } internal static IDataBoundControlInterface GetControlAdapter(Control control) { #if ORYX_VNEXT if (control is GridView) return new GridViewAdapter((GridView)control); if (control is DetailsView) return new DetailsViewAdapter((DetailsView)control); if (control is ListView) return new ListViewAdapter((ListView)control); if (control is FormView) return new FormViewAdapter((FormView)control); if (control is Repeater) { return new RepeaterAdapter((Repeater)control); } if (control is DataBoundControl) { return new DataBoundControlAdapter((DataBoundControl)control); } #else Repeater repeater = control as Repeater; if (repeater != null) { return new RepeaterDataBoundAdapter(repeater); } #endif return null; } } #if ORYX_VNEXT // Adapters hierarchy // BaseDataControlAdapter: IDataBoundControl // DataBoundControlAdapter // DataBoundControlParameterTargetAdapter: IControlParameterTarget // GridViewAdapter // DetailsViewAdapter // FormViewAdapter // ListViewAdapter // RepeaterAdapter abstract class BaseDataControlAdapter : IDataBoundControl { #region IDataBoundControl Members public virtual string[] DataKeyNames { get { return null; } set { } } public virtual DataKeyArray DataKeys { get { return null; } } public abstract string DataSourceID { get; } public virtual IDynamicDataSource DataSourceObject { get { return null; } } public abstract object DataSource { get; } public virtual bool EnableModelValidation { get { return false; } set { } } public virtual DataControlFieldCollection Fields { get { return null; } } public virtual IAutoFieldGenerator FieldsGenerator { get { return null; } set { } } public virtual DataBoundControlMode Mode { get { throw new NotImplementedException(); } } public virtual DataKey SelectedDataKey { get { throw new NotImplementedException(); } } public virtual int SelectedIndex { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } #endregion } class DataBoundControlAdapter : BaseDataControlAdapter { private DataBoundControl _dataBoundControl; public DataBoundControlAdapter(DataBoundControl dataBoundControl) { _dataBoundControl = dataBoundControl; } public override string DataSourceID { get { return _dataBoundControl.DataSourceID; } } public override IDynamicDataSource DataSourceObject { get { return _dataBoundControl.DataSourceObject as IDynamicDataSource; } } public override object DataSource { get { return _dataBoundControl.DataSource; } } } abstract class DataBoundControlParameterTargetAdapter : DataBoundControlAdapter, IControlParameterTarget { public DataBoundControlParameterTargetAdapter(DataBoundControl dataBoundControl) : base(dataBoundControl) { } #region IControlParameterTarget Members public virtual MetaTable Table { get { return DataSourceObject.GetTable(); } } public virtual MetaColumn FilteredColumn { get { return null; } } public abstract string GetPropertyNameExpression(string columnName); #endregion } class GridViewAdapter : DataBoundControlParameterTargetAdapter { private GridView _gridView; public GridViewAdapter(GridView gridView) : base(gridView) { _gridView = gridView; } #region IDataBoundControl Members public override string[] DataKeyNames { get { return _gridView.DataKeyNames; } set { _gridView.DataKeyNames = value; } } public override DataKeyArray DataKeys { get { return _gridView.DataKeys; } } public override bool EnableModelValidation { get { return _gridView.EnableModelValidation; } set { _gridView.EnableModelValidation = value; } } public override DataControlFieldCollection Fields { get { return _gridView.Columns; } } public override IAutoFieldGenerator FieldsGenerator { get { return _gridView.ColumnsGenerator; } set { _gridView.ColumnsGenerator = value; } } public override DataBoundControlMode Mode { get { return (_gridView.EditIndex >= 0) ? DataBoundControlMode.Edit : DataBoundControlMode.ReadOnly; } } public override DataKey SelectedDataKey { get { return _gridView.SelectedDataKey; } } public override int SelectedIndex { get { return _gridView.SelectedIndex; } set { _gridView.SelectedIndex = value; } } #endregion #region IControlParameterTarget Members public override string GetPropertyNameExpression(string columnName) { return String.Format(CultureInfo.InvariantCulture, "SelectedPersistedDataKey['{0}']", columnName); } #endregion } class DetailsViewAdapter : DataBoundControlParameterTargetAdapter { private DetailsView _detailsView; public DetailsViewAdapter(DetailsView detailsView) : base(detailsView) { _detailsView = detailsView; } #region IDataBoundControl Members public override string[] DataKeyNames { get { return _detailsView.DataKeyNames; } set { _detailsView.DataKeyNames = value; } } public override bool EnableModelValidation { get { return _detailsView.EnableModelValidation; } set { _detailsView.EnableModelValidation = value; } } public override DataControlFieldCollection Fields { get { return _detailsView.Fields; } } public override IAutoFieldGenerator FieldsGenerator { get { return _detailsView.RowsGenerator; } set { _detailsView.RowsGenerator = value; } } public override DataBoundControlMode Mode { get { switch (_detailsView.CurrentMode) { case DetailsViewMode.Edit: return DataBoundControlMode.Edit; case DetailsViewMode.Insert: return DataBoundControlMode.Insert; default: return DataBoundControlMode.ReadOnly; } } } public override DataKey SelectedDataKey { get { return _detailsView.DataKey; } } #endregion #region IControlParameterTarget Members public override string GetPropertyNameExpression(string columnName) { return String.Format(CultureInfo.InvariantCulture, "DataKey['{0}']", columnName); } #endregion } class FormViewAdapter : DataBoundControlParameterTargetAdapter { private FormView _formView; public FormViewAdapter(FormView formView) : base(formView) { _formView = formView; } #region IDataBoundControl Members public override string[] DataKeyNames { get { return _formView.DataKeyNames; } set { _formView.DataKeyNames = value; } } public override bool EnableModelValidation { get { return _formView.EnableModelValidation; } set { _formView.EnableModelValidation = value; } } public override DataBoundControlMode Mode { get { switch (_formView.CurrentMode) { case FormViewMode.Edit: return DataBoundControlMode.Edit; case FormViewMode.Insert: return DataBoundControlMode.Insert; default: return DataBoundControlMode.ReadOnly; } } } public override DataKey SelectedDataKey { get { return _formView.DataKey; } } #endregion #region IControlParameterTarget Members public override string GetPropertyNameExpression(string columnName) { return String.Format(CultureInfo.InvariantCulture, "DataKey['{0}']", columnName); } #endregion } class ListViewAdapter : DataBoundControlParameterTargetAdapter { private ListView _listView; public ListViewAdapter(ListView listView) : base(listView) { _listView = listView; } #region IDataBoundControl Members public override string[] DataKeyNames { get { return _listView.DataKeyNames; } set { _listView.DataKeyNames = value; } } public override DataKeyArray DataKeys { get { return _listView.DataKeys; } } public override bool EnableModelValidation { get { return _listView.EnableModelValidation; } set { _listView.EnableModelValidation = value; } } public override DataBoundControlMode Mode { get { return (_listView.EditIndex >= 0) ? DataBoundControlMode.Edit : DataBoundControlMode.ReadOnly; } } public override DataKey SelectedDataKey { get { return _listView.SelectedDataKey; } } public override int SelectedIndex { get { return _listView.SelectedIndex; } set { _listView.SelectedIndex = value; } } #endregion #region IControlParameterTarget Members public override string GetPropertyNameExpression(string columnName) { return String.Format(CultureInfo.InvariantCulture, "SelectedPersistedDataKey['{0}']", columnName); } #endregion } class RepeaterAdapter : BaseDataControlAdapter { private Repeater _repeater; public RepeaterAdapter(Repeater repeater) { _repeater = repeater; } public override string DataSourceID { get { return _repeater.DataSourceID; } } public override IDynamicDataSource DataSourceObject { get { return Misc.FindControl(_repeater, DataSourceID) as IDynamicDataSource; } } public override object DataSource { get { return _repeater.DataSource; } } } interface IDataBoundControl { string[] DataKeyNames { get; set; } DataKeyArray DataKeys { get; } string DataSourceID { get; } IDynamicDataSource DataSourceObject { get; } object DataSource { get; } bool EnableModelValidation { get; set; } DataControlFieldCollection Fields { get; } IAutoFieldGenerator FieldsGenerator { get; set; } DataBoundControlMode Mode { get; } DataKey SelectedDataKey { get; } int SelectedIndex { get; set; } } #endif } // 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
- DataStreamFromComStream.cs
- ExtendedPropertyInfo.cs
- SqlIdentifier.cs
- TokenBasedSetEnumerator.cs
- SqlMethods.cs
- NotSupportedException.cs
- Columns.cs
- AssociatedControlConverter.cs
- OrderedDictionary.cs
- NotificationContext.cs
- PerfCounterSection.cs
- PersonalizationProviderHelper.cs
- ObjectCloneHelper.cs
- HttpPostServerProtocol.cs
- ActivityDesignerHelper.cs
- WindowsStatusBar.cs
- ISAPIApplicationHost.cs
- StringArrayEditor.cs
- _LocalDataStoreMgr.cs
- HasCopySemanticsAttribute.cs
- ScriptManagerProxy.cs
- RequestCache.cs
- DataGridView.cs
- DesignTimeVisibleAttribute.cs
- TypeReference.cs
- SiteMapDataSource.cs
- RegexStringValidator.cs
- DragDeltaEventArgs.cs
- StyleBamlTreeBuilder.cs
- BamlStream.cs
- ResponseBodyWriter.cs
- OuterGlowBitmapEffect.cs
- DesignerDataTableBase.cs
- DelegatingTypeDescriptionProvider.cs
- ScrollProviderWrapper.cs
- CommandValueSerializer.cs
- StoreItemCollection.cs
- CursorInteropHelper.cs
- OutputCacheSettingsSection.cs
- DataMisalignedException.cs
- FilterEventArgs.cs
- SyndicationFeed.cs
- ObjectTokenCategory.cs
- XmlElementAttribute.cs
- MatrixAnimationUsingKeyFrames.cs
- MultiView.cs
- CancellationHandler.cs
- ToolStripDropDownClosedEventArgs.cs
- RadioButtonRenderer.cs
- CommandLineParser.cs
- Assert.cs
- M3DUtil.cs
- LineBreakRecord.cs
- ToolStripItemImageRenderEventArgs.cs
- XPathItem.cs
- XmlFormatWriterGenerator.cs
- Ops.cs
- CompModSwitches.cs
- DataSourceXmlElementAttribute.cs
- OrderedDictionary.cs
- SpStreamWrapper.cs
- XmlEnumAttribute.cs
- InternalSafeNativeMethods.cs
- Composition.cs
- Selector.cs
- DeferredSelectedIndexReference.cs
- HostedTransportConfigurationBase.cs
- MediaPlayer.cs
- DocumentEventArgs.cs
- RangeValidator.cs
- Attachment.cs
- Viewport2DVisual3D.cs
- SlotInfo.cs
- SystemThemeKey.cs
- AuthenticateEventArgs.cs
- GeneratedContractType.cs
- BulletedListEventArgs.cs
- RolePrincipal.cs
- RuleElement.cs
- ImageDrawing.cs
- ObjectListFieldsPage.cs
- Point3DAnimationUsingKeyFrames.cs
- CaseInsensitiveComparer.cs
- TriState.cs
- BigInt.cs
- EmptyControlCollection.cs
- CommonDialog.cs
- WorkflowPersistenceService.cs
- MetadataCollection.cs
- Exceptions.cs
- TemplatedEditableDesignerRegion.cs
- dsa.cs
- DependencyPropertyHelper.cs
- wgx_sdk_version.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- MSAAEventDispatcher.cs
- ListComponentEditorPage.cs
- COM2ColorConverter.cs
- HelpInfo.cs
- GlyphManager.cs