private IHierarchicalDataSource ConnectToHierarchicalDataSource() { if (this._currentDataSourceValid && !base.DesignMode) { if ((!this._currentDataSourceIsFromControl && (this.DataSourceID != null)) && (this.DataSourceID.Length != 0)) { throw new InvalidOperationException(System.Web.SR.GetString("DataControl_MultipleDataSources", new object[] { this.ID })); } return(this._currentHierarchicalDataSource); } if ((this._currentHierarchicalDataSource != null) && this._currentDataSourceIsFromControl) { this._currentHierarchicalDataSource.DataSourceChanged -= new EventHandler(this.OnDataSourceChanged); } this._currentHierarchicalDataSource = this.GetDataSource(); this._currentDataSourceIsFromControl = base.IsBoundUsingDataSourceID; if (this._currentHierarchicalDataSource == null) { this._currentHierarchicalDataSource = new ReadOnlyHierarchicalDataSource(this.DataSource); } else if (this.DataSource != null) { throw new InvalidOperationException(System.Web.SR.GetString("DataControl_MultipleDataSources", new object[] { this.ID })); } this._currentDataSourceValid = true; if ((this._currentHierarchicalDataSource != null) && this._currentDataSourceIsFromControl) { this._currentHierarchicalDataSource.DataSourceChanged += new EventHandler(this.OnDataSourceChanged); } return(this._currentHierarchicalDataSource); }
private IHierarchicalDataSource ConnectToHierarchicalDataSource() { if (this._currentDataSourceValid && !base.DesignMode) { if ((!this._currentDataSourceIsFromControl && (this.DataSourceID != null)) && (this.DataSourceID.Length != 0)) { throw new InvalidOperationException(System.Web.SR.GetString("DataControl_MultipleDataSources", new object[] { this.ID })); } return this._currentHierarchicalDataSource; } if ((this._currentHierarchicalDataSource != null) && this._currentDataSourceIsFromControl) { this._currentHierarchicalDataSource.DataSourceChanged -= new EventHandler(this.OnDataSourceChanged); } this._currentHierarchicalDataSource = this.GetDataSource(); this._currentDataSourceIsFromControl = base.IsBoundUsingDataSourceID; if (this._currentHierarchicalDataSource == null) { this._currentHierarchicalDataSource = new ReadOnlyHierarchicalDataSource(this.DataSource); } else if (this.DataSource != null) { throw new InvalidOperationException(System.Web.SR.GetString("DataControl_MultipleDataSources", new object[] { this.ID })); } this._currentDataSourceValid = true; if ((this._currentHierarchicalDataSource != null) && this._currentDataSourceIsFromControl) { this._currentHierarchicalDataSource.DataSourceChanged += new EventHandler(this.OnDataSourceChanged); } return this._currentHierarchicalDataSource; }
/// <devdoc> /// Gets the IHierarchicalDataSource that this control is bound to, if any. /// </devdoc> protected virtual IHierarchicalDataSource GetDataSource() { if (!DesignMode && _currentDataSourceValid && (_currentHierarchicalDataSource != null)) { return(_currentHierarchicalDataSource); } IHierarchicalDataSource ds = null; string dataSourceID = DataSourceID; if (dataSourceID.Length != 0) { // Try to find a DataSource control with the ID specified in DataSourceID Control control = DataBoundControlHelper.FindControl(this, dataSourceID); if (control == null) { throw new HttpException(SR.GetString(SR.HierarchicalDataControl_DataSourceDoesntExist, ID, dataSourceID)); } ds = control as IHierarchicalDataSource; if (ds == null) { throw new HttpException(SR.GetString(SR.HierarchicalDataControl_DataSourceIDMustBeHierarchicalDataControl, ID, dataSourceID)); } } return(ds); }
void Initialize() { if (!Page.IsPostBack || (IsViewStateEnabled && !IsDataBound)) { RequiresDataBinding = true; } IHierarchicalDataSource ds = GetDataSource(); if (ds != null && DataSourceID != "") { ds.DataSourceChanged += new EventHandler(OnDataSourceChanged); } }
/// <devdoc> /// Connects this hierarchical data bound control to the appropriate /// HierarchicalDataSource and hooks up the appropriate event listener /// for the DataSourceChanged event. The return value is the new data source /// (if any) that was connected to. An exception is thrown if there is /// a problem finding the requested data source. /// </devdoc> private IHierarchicalDataSource ConnectToHierarchicalDataSource() { if (_currentDataSourceValid && !DesignMode) { // Ensure that both DataSourceID as well as DataSource are not set at the same time if (!_currentDataSourceIsFromControl && DataSourceID != null && DataSourceID.Length != 0) { throw new InvalidOperationException(SR.GetString(SR.DataControl_MultipleDataSources, ID)); } // If the current view is correct, there is no need to reconnect return(_currentHierarchicalDataSource); } // Disconnect from old view, if necessary if ((_currentHierarchicalDataSource != null) && (_currentDataSourceIsFromControl)) { // We only care about this event if we are bound through the DataSourceID property _currentHierarchicalDataSource.DataSourceChanged -= new EventHandler(OnDataSourceChanged); } // Connect to new view _currentHierarchicalDataSource = GetDataSource(); _currentDataSourceIsFromControl = IsBoundUsingDataSourceID; if (_currentHierarchicalDataSource == null) { // HierarchicalDataSource control was not found, construct a temporary data source to wrap the data _currentHierarchicalDataSource = new ReadOnlyHierarchicalDataSource(DataSource); } else { // Ensure that both DataSourceID as well as DataSource are not set at the same time if (DataSource != null) { throw new InvalidOperationException(SR.GetString(SR.DataControl_MultipleDataSources, ID)); } } _currentDataSourceValid = true; if ((_currentHierarchicalDataSource != null) && (_currentDataSourceIsFromControl)) { // We only care about this event if we are bound through the DataSourceID property _currentHierarchicalDataSource.DataSourceChanged += new EventHandler(OnDataSourceChanged); } return(_currentHierarchicalDataSource); }
HierarchicalDataSourceView IHierarchicalDataSource.GetHierarchicalView(string viewPath) { IHierarchicalDataSource source = this._dataSource as IHierarchicalDataSource; if (source != null) { return(source.GetHierarchicalView(viewPath)); } IHierarchicalEnumerable dataSource = this._dataSource as IHierarchicalEnumerable; if (((dataSource != null) && (viewPath != null)) && (viewPath.Length != 0)) { throw new InvalidOperationException(System.Web.SR.GetString("ReadOnlyHierarchicalDataSourceView_CantAccessPathInEnumerable")); } return(new ReadOnlyHierarchicalDataSourceView(dataSource)); }
/// <devdoc> /// Check for IHierarchicalDataSource and IHierarchicalEnumerable, and /// return an approprite HierarchicalDataSourceView. /// </devdoc> HierarchicalDataSourceView IHierarchicalDataSource.GetHierarchicalView(string viewPath) { // Check first for IHierarchicalDataSource IHierarchicalDataSource ds = _dataSource as IHierarchicalDataSource; if (ds != null) { return(ds.GetHierarchicalView(viewPath)); } IHierarchicalEnumerable enumerable = _dataSource as IHierarchicalEnumerable; if (enumerable != null && viewPath != null && viewPath.Length != 0) { throw new InvalidOperationException(SR.GetString(SR.ReadOnlyHierarchicalDataSourceView_CantAccessPathInEnumerable)); } return(new ReadOnlyHierarchicalDataSourceView(enumerable)); }
/// <devdoc> /// Gets the HierarchicalDataSourceView of the IHierarchicalDataSource /// that this control is bound to, if any. /// </devdoc> protected virtual HierarchicalDataSourceView GetData(string viewPath) { string currentViewPath = viewPath; IHierarchicalDataSource ds = ConnectToHierarchicalDataSource(); Debug.Assert(_currentDataSourceValid); Debug.Assert(ds != null); // IHierarchicalDataSource was found, extract the appropriate view and return it HierarchicalDataSourceView view = ds.GetHierarchicalView(currentViewPath); if (view == null) { throw new InvalidOperationException(SR.GetString(SR.HierarchicalDataControl_ViewNotFound, ID)); } return(view); }
protected virtual HierarchicalDataSourceView GetData(string viewPath) { if (DataSource != null && DataSourceID != "") { throw new HttpException(); } IHierarchicalDataSource ds = GetDataSource(); if (ds != null) { return(ds.GetHierarchicalView(viewPath)); } if (DataSource is IHierarchicalEnumerable) { return(new ReadOnlyDataSourceView((IHierarchicalEnumerable)DataSource)); } return(null); }
/// <devdoc> /// Connects this hierarchical data bound control to the appropriate /// HierarchicalDataSource and hooks up the appropriate event listener /// for the DataSourceChanged event. The return value is the new data source /// (if any) that was connected to. An exception is thrown if there is /// a problem finding the requested data source. /// </devdoc> private IHierarchicalDataSource ConnectToHierarchicalDataSource() { if (_currentDataSourceValid && !DesignMode) { // Ensure that both DataSourceID as well as DataSource are not set at the same time if (!_currentDataSourceIsFromControl && DataSourceID != null && DataSourceID.Length != 0) { throw new InvalidOperationException(SR.GetString(SR.DataControl_MultipleDataSources, ID)); } // If the current view is correct, there is no need to reconnect return _currentHierarchicalDataSource; } // Disconnect from old view, if necessary if ((_currentHierarchicalDataSource != null) && (_currentDataSourceIsFromControl)) { // We only care about this event if we are bound through the DataSourceID property _currentHierarchicalDataSource.DataSourceChanged -= new EventHandler(OnDataSourceChanged); } // Connect to new view _currentHierarchicalDataSource = GetDataSource(); _currentDataSourceIsFromControl = IsBoundUsingDataSourceID; if (_currentHierarchicalDataSource == null) { // HierarchicalDataSource control was not found, construct a temporary data source to wrap the data _currentHierarchicalDataSource = new ReadOnlyHierarchicalDataSource(DataSource); } else { // Ensure that both DataSourceID as well as DataSource are not set at the same time if (DataSource != null) { throw new InvalidOperationException(SR.GetString(SR.DataControl_MultipleDataSources, ID)); } } _currentDataSourceValid = true; if ((_currentHierarchicalDataSource != null) && (_currentDataSourceIsFromControl)) { // We only care about this event if we are bound through the DataSourceID property _currentHierarchicalDataSource.DataSourceChanged += new EventHandler(OnDataSourceChanged); } return _currentHierarchicalDataSource; }
protected void ASPxCallback1_Callback(object sender, CallbackEventArgs e) { int newsID = int.Parse(e.Parameter); IHierarchicalDataSource dataSource = (IHierarchicalDataSource)XmlDataSource1; HierarchicalDataSourceView view = dataSource.GetHierarchicalView(""); IHierarchicalEnumerable enumerable = view.Select(); int index = 1; string text = ""; foreach (object obj in enumerable) { if (newsID == index) { IHierarchyData data = enumerable.GetHierarchyData(obj); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(data); PropertyDescriptor descriptor = properties.Find("Text", true); text = descriptor.GetValue(obj).ToString(); break; } index++; } e.Result = text; }
protected virtual IHierarchicalDataSource GetDataSource() { if ((!base.DesignMode && this._currentDataSourceValid) && (this._currentHierarchicalDataSource != null)) { return(this._currentHierarchicalDataSource); } IHierarchicalDataSource source = null; string dataSourceID = this.DataSourceID; if (dataSourceID.Length != 0) { Control control = DataBoundControlHelper.FindControl(this, dataSourceID); if (control == null) { throw new HttpException(System.Web.SR.GetString("HierarchicalDataControl_DataSourceDoesntExist", new object[] { this.ID, dataSourceID })); } source = control as IHierarchicalDataSource; if (source == null) { throw new HttpException(System.Web.SR.GetString("HierarchicalDataControl_DataSourceIDMustBeHierarchicalDataControl", new object[] { this.ID, dataSourceID })); } } return(source); }