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
- SqlHelper.cs
- XhtmlConformanceSection.cs
- RawContentTypeMapper.cs
- Misc.cs
- IntSecurity.cs
- ValidationError.cs
- StylusPointProperty.cs
- WindowsFormsSynchronizationContext.cs
- WebPartConnectionsEventArgs.cs
- NavigationCommands.cs
- ParserStreamGeometryContext.cs
- WindowsSlider.cs
- PipelineModuleStepContainer.cs
- _DisconnectOverlappedAsyncResult.cs
- PackageRelationshipCollection.cs
- DoubleLinkListEnumerator.cs
- PeerCollaboration.cs
- SingleAnimation.cs
- FunctionImportElement.cs
- XmlTextEncoder.cs
- IndividualDeviceConfig.cs
- DateTimePickerDesigner.cs
- TypedTableBase.cs
- SqlEnums.cs
- CurrencyWrapper.cs
- TextViewSelectionProcessor.cs
- odbcmetadatacolumnnames.cs
- LogWriteRestartAreaAsyncResult.cs
- GetFileNameResult.cs
- XmlBinaryWriterSession.cs
- DataColumn.cs
- QueryStringConverter.cs
- CheckedPointers.cs
- SingletonConnectionReader.cs
- SetMemberBinder.cs
- DataGridItem.cs
- UnSafeCharBuffer.cs
- WeakReadOnlyCollection.cs
- StringFormat.cs
- FlowDocumentPage.cs
- hebrewshape.cs
- WebServiceParameterData.cs
- DiscreteKeyFrames.cs
- TypeSystem.cs
- SelectionHighlightInfo.cs
- CapabilitiesState.cs
- XPathExpr.cs
- ByteStream.cs
- InstanceKeyView.cs
- GiveFeedbackEventArgs.cs
- EmptyCollection.cs
- BitStack.cs
- IFormattable.cs
- ProgressBarRenderer.cs
- UnsettableComboBox.cs
- EpmCustomContentSerializer.cs
- SHA1CryptoServiceProvider.cs
- _AutoWebProxyScriptWrapper.cs
- HtmlTableRowCollection.cs
- JsonWriter.cs
- DataBindingsDialog.cs
- TextBox.cs
- DataGridViewRowPrePaintEventArgs.cs
- IisTraceListener.cs
- PartitionedStreamMerger.cs
- CachedTypeface.cs
- AssemblyName.cs
- GroupBoxRenderer.cs
- ExpandCollapseIsCheckedConverter.cs
- AccessKeyManager.cs
- ToolStripProgressBar.cs
- InputLanguageProfileNotifySink.cs
- EllipseGeometry.cs
- SqlTriggerAttribute.cs
- SkinBuilder.cs
- DrawingVisual.cs
- ConfigurationPropertyAttribute.cs
- OracleParameter.cs
- ErrorReporting.cs
- CellRelation.cs
- OAVariantLib.cs
- SmiXetterAccessMap.cs
- ServerValidateEventArgs.cs
- SafeNativeMethods.cs
- ScriptingRoleServiceSection.cs
- GeneralTransform3DCollection.cs
- MetafileHeader.cs
- RectValueSerializer.cs
- GeneralTransformCollection.cs
- ByteStack.cs
- TypeBrowserDialog.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- DbSource.cs
- DataSourceViewSchemaConverter.cs
- TrackingServices.cs
- FontCollection.cs
- HashSetEqualityComparer.cs
- PrePostDescendentsWalker.cs
- Metafile.cs
- While.cs