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
- WebBrowser.cs
- CodeAccessSecurityEngine.cs
- XmlSortKey.cs
- ColorMap.cs
- ControlCachePolicy.cs
- SvcMapFileSerializer.cs
- BitSet.cs
- DefaultPrintController.cs
- DataGridViewCellStyleEditor.cs
- ViewPort3D.cs
- DataGridViewTextBoxColumn.cs
- mediapermission.cs
- StylusShape.cs
- FormatConvertedBitmap.cs
- DataColumnPropertyDescriptor.cs
- MailWriter.cs
- ConstNode.cs
- ExpressionConverter.cs
- EdmItemError.cs
- HttpServerVarsCollection.cs
- HeaderedContentControl.cs
- CompiledXpathExpr.cs
- XmlAttributeOverrides.cs
- Currency.cs
- CryptoKeySecurity.cs
- CaseInsensitiveHashCodeProvider.cs
- LoginStatusDesigner.cs
- PropertyValueUIItem.cs
- VisualBrush.cs
- UrlPropertyAttribute.cs
- FilteredDataSetHelper.cs
- SpeechSynthesizer.cs
- DbSourceCommand.cs
- HttpListenerException.cs
- ArraySegment.cs
- SystemMulticastIPAddressInformation.cs
- SemanticResultValue.cs
- AsyncInvokeOperation.cs
- HierarchicalDataSourceControl.cs
- Compensate.cs
- CleanUpVirtualizedItemEventArgs.cs
- dsa.cs
- DataContext.cs
- Hashtable.cs
- DataMember.cs
- InputManager.cs
- ToolboxItemCollection.cs
- EmptyCollection.cs
- CombinedTcpChannel.cs
- SortFieldComparer.cs
- diagnosticsswitches.cs
- AnnotationDocumentPaginator.cs
- NativeMethods.cs
- SpellerStatusTable.cs
- ColorTranslator.cs
- ValuePatternIdentifiers.cs
- GeometryDrawing.cs
- WasEndpointConfigContainer.cs
- GridViewRowPresenter.cs
- DBSchemaRow.cs
- BitmapEffectInputConnector.cs
- WebDisplayNameAttribute.cs
- X509CertificateCollection.cs
- configsystem.cs
- ObjectManager.cs
- TextEditorSelection.cs
- PersonalizationProvider.cs
- DynamicMethod.cs
- RIPEMD160.cs
- glyphs.cs
- PagedControl.cs
- EncoderNLS.cs
- HtmlShim.cs
- SeverityFilter.cs
- StringBuilder.cs
- Pair.cs
- XamlStream.cs
- TriggerActionCollection.cs
- ParallelTimeline.cs
- HealthMonitoringSectionHelper.cs
- XmlDataImplementation.cs
- Vector3DCollectionConverter.cs
- CssStyleCollection.cs
- ReadOnlyDataSource.cs
- LockCookie.cs
- DesignerToolStripControlHost.cs
- NullableBoolConverter.cs
- InstanceKeyView.cs
- PersonalizationProviderCollection.cs
- ProjectionCamera.cs
- ActiveXContainer.cs
- CellTreeNode.cs
- ChannelBinding.cs
- Property.cs
- ListViewPagedDataSource.cs
- AnnotationResourceCollection.cs
- TableLayoutPanelCellPosition.cs
- DirectoryInfo.cs
- DataKeyCollection.cs
- ScrollEventArgs.cs