/// <summary> /// Call base control's CreateChildControls method and determine the number of rows in the source /// then fire off the event with the derived data and then we return the original result. /// </summary> /// <param name="dataSource"></param> /// <param name="dataBinding"></param> /// <returns></returns> protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding) { int rows = base.CreateChildControls(dataSource, dataBinding); // if the paging feature is enabled, determine the total number of rows in the datasource if (this.AllowPaging) { // if we are databinding, use the number of rows that were created, otherwise cast the datasource to an Collection and use that as the count int totalRowCount = dataBinding ? rows : ((ICollection)dataSource).Count; // raise the row count available event IPageableItemContainer pageableItemContainer = this as IPageableItemContainer; this.OnTotalRowCountAvailable(new PageEventArgs(pageableItemContainer.StartRowIndex, pageableItemContainer.MaximumRows, totalRowCount)); // make sure the top and bottom pager rows are not visible if (this.TopPagerRow != null) { this.TopPagerRow.Visible = false; } if (this.BottomPagerRow != null) { this.BottomPagerRow.Visible = false; } } return(rows); }
protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding) { int rows = base.CreateChildControls(dataSource, dataBinding); if (this.AllowPaging || this.AllowSorting) { if (dataSource != null && dataSource.GetType().ToString() != "System.Web.UI.WebControls.DummyDataSource") { GVDataSource = dataSource; SetHeaderRows(); } } if (this.AllowPaging) { int totalRowCount = dataBinding ? rows : ((ICollection)dataSource).Count; IPageableItemContainer pageableItemContainer = this as IPageableItemContainer; this.OnTotalRowCountAvailable(new PageEventArgs(pageableItemContainer.StartRowIndex, pageableItemContainer.MaximumRows, totalRowCount)); if (this.TopPagerRow != null) { this.TopPagerRow.Visible = false; } if (this.BottomPagerRow != null) { this.BottomPagerRow.Visible = false; } } return(rows); }
protected internal override void OnLoad(EventArgs e) { if (_pageableItemContainer == null) { _pageableItemContainer = FindPageableItemContainer(); } if (_pageableItemContainer == null) { throw new InvalidOperationException(AtlasWeb.DataPager_NoPageableItemContainer); } // Page properties may not have been set in OnInit because the IPageableItemContainer // could have been added in OnLoad if (!_setPageProperties) { ConnectToEvents(_pageableItemContainer); if (!String.IsNullOrEmpty(QueryStringField)) { _startRowIndex = GetStartRowIndexFromQueryString(); } _pageableItemContainer.SetPageProperties(_startRowIndex, _maximumRows, false); _setPageProperties = true; } base.OnLoad(e); }
protected internal override void OnInit(EventArgs e) { base.OnInit(e); // We can't try to find another control in the designer in Init. if (!DesignMode) { _pageableItemContainer = FindPageableItemContainer(); if (_pageableItemContainer != null) { ConnectToEvents(_pageableItemContainer); if (!String.IsNullOrEmpty(QueryStringField)) { _startRowIndex = GetStartRowIndexFromQueryString(); } _pageableItemContainer.SetPageProperties(_startRowIndex, _maximumRows, false); _setPageProperties = true; } if (Page != null) { Page.RegisterRequiresControlState(this); } } _initialized = true; }
protected virtual void ConnectToEvents(IPageableItemContainer container) { if (container == null) { throw new ArgumentNullException("container"); } container.TotalRowCountAvailable += new EventHandler <PageEventArgs> (OnTotalRowCountAvailable); }
protected internal override void OnLoad(EventArgs e) { if (_pageableContainer == null) { _pageableContainer = FindPageableItemContainer(); } if (_pageableContainer == null) { throw new InvalidOperationException(_exceptionMessages [NO_PAGEABLE_ITEM_CONTAINER]); } SetUpForNewContainer(false, false); base.OnLoad(e); }
/// <devdoc> /// <para>Loads the control state for those properties that should persist across postbacks /// even when EnableViewState=false.</para> /// </devdoc> protected internal override void LoadControlState(object savedState) { // Any properties that could have been set in the persistance need to be // restored to their defaults if they're not in ControlState, or they will // be restored to their persisted state instead of their empty state. _startRowIndex = 0; _maximumRows = 10; _totalRowCount = -1; object[] state = savedState as object[]; if (state != null) { base.LoadControlState(state[0]); if (state[1] != null) { _startRowIndex = (int)state[1]; } if (state[2] != null) { _maximumRows = (int)state[2]; } if (state[3] != null) { _totalRowCount = (int)state[3]; } } else { base.LoadControlState(null); } if (_pageableItemContainer == null) { _pageableItemContainer = FindPageableItemContainer(); if (_pageableItemContainer == null) { throw new InvalidOperationException(AtlasWeb.DataPager_NoPageableItemContainer); } ConnectToEvents(_pageableItemContainer); } _pageableItemContainer.SetPageProperties(_startRowIndex, _maximumRows, false); _setPageProperties = true; }
protected virtual IPageableItemContainer FindPageableItemContainer() { // the PagedControlID can be specified for finding a control within the same naming container // when the pager control isn't inside the IPageableItemContainter. if (!String.IsNullOrEmpty(PagedControlID)) { // The IPageableItemContainer is found by FindControl if specified. Control control = DataBoundControlHelper.FindControl(this, PagedControlID); if (control == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.DataPager_PageableItemContainerNotFound, PagedControlID)); } IPageableItemContainer container = control as IPageableItemContainer; if (container == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.DataPager_ControlIsntPageable, PagedControlID)); } return(container); } else { // Look to see if parent container is IPageableItemContainer Control currentContainer = this.NamingContainer; IPageableItemContainer foundContainer = null; while (foundContainer == null && currentContainer != this.Page) { if (currentContainer == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.DataPager_NoNamingContainer, ID)); } foundContainer = currentContainer as IPageableItemContainer; currentContainer = currentContainer.NamingContainer; } return(foundContainer); } }
protected internal override void OnInit(EventArgs e) { base.OnInit(e); Page page = Page; if (page != null) { page.RegisterRequiresControlState(this); } // It might return null here - there is no guarantee all the controls on the // page are already initialized by the time this method is loaded. Do not // throw for that reason. _pageableContainer = FindPageableItemContainer(); if (_pageableContainer != null) { // Do not re-bind the data here - not all the controls might be // initialized (that includes the container may be bound to) SetUpForNewContainer(false, true); } _initDone = true; }
protected internal override void LoadControlState(object savedState) { object[] state = savedState as object[]; object tmp; if (state != null && state.Length == CSTATE_COUNT) { base.LoadControlState(state [CSTATE_BASE_STATE]); if ((tmp = state [CSTATE_TOTAL_ROW_COUNT]) != null) { _totalRowCount = (int)tmp; } if ((tmp = state [CSTATE_MAXIMUM_ROWS]) != null) { _maximumRows = (int)tmp; } if ((tmp = state [CSTATE_START_ROW_INDEX]) != null) { _startRowIndex = (int)tmp; } } if (_pageableContainer == null) { _pageableContainer = FindPageableItemContainer(); if (_pageableContainer == null) { throw new InvalidOperationException(_exceptionMessages [NO_DATABOUND_CONTROL]); } ConnectToEvents(_pageableContainer); } SetUpForNewContainer(false, false); }
protected virtual void ConnectToEvents(IPageableItemContainer container) { if (container == null) { throw new ArgumentNullException("container"); } // _pageableItemContainer.TotalRowCountAvailable += new EventHandler<PageEventArgs>(OnTotalRowCountAvailable); }
protected internal override void OnLoad (EventArgs e) { if (_pageableContainer == null) _pageableContainer = FindPageableItemContainer (); if (_pageableContainer == null) throw new InvalidOperationException (_exceptionMessages [NO_PAGEABLE_ITEM_CONTAINER]); SetUpForNewContainer (false, false); base.OnLoad (e); }
protected internal override void OnInit (EventArgs e) { base.OnInit (e); Page page = Page; if (page != null) page.RegisterRequiresControlState (this); // It might return null here - there is no guarantee all the controls on the // page are already initialized by the time this method is loaded. Do not // throw for that reason. _pageableContainer = FindPageableItemContainer (); if (_pageableContainer != null) // Do not re-bind the data here - not all the controls might be // initialized (that includes the container may be bound to) SetUpForNewContainer (false, true); _initDone = true; }
protected internal override void LoadControlState (object savedState) { object[] state = savedState as object[]; object tmp; if (state != null && state.Length == CSTATE_COUNT) { base.LoadControlState (state [CSTATE_BASE_STATE]); if ((tmp = state [CSTATE_TOTAL_ROW_COUNT]) != null) _totalRowCount = (int) tmp; if ((tmp = state [CSTATE_MAXIMUM_ROWS]) != null) _maximumRows = (int) tmp; if ((tmp = state [CSTATE_START_ROW_INDEX]) != null) _startRowIndex = (int) tmp; } if (_pageableContainer == null) { _pageableContainer = FindPageableItemContainer (); if (_pageableContainer == null) throw new InvalidOperationException (_exceptionMessages [NO_DATABOUND_CONTROL]); ConnectToEvents (_pageableContainer); } SetUpForNewContainer (false, false); }
protected virtual IPageableItemContainer FindPageableItemContainer() { string pagedControlID = PagedControlID; IPageableItemContainer ret = null; Page page = Page; Control container; if (page != null && !String.IsNullOrEmpty(pagedControlID)) { Control ctl = null; container = NamingContainer; while (container != null) { ctl = container.FindControl(pagedControlID); if (ctl != null) { break; } if (container == page) { break; } container = container.NamingContainer; } if (container == null) { throw new InvalidOperationException(_exceptionMessages [NO_NAMING_CONTAINER]); } if (ctl == null) { throw new InvalidOperationException(String.Format(_exceptionMessages [NO_PAGED_CONTAINER_ID], pagedControlID)); } ret = ctl as IPageableItemContainer; if (ret == null) { throw new InvalidOperationException(String.Format(_exceptionMessages [CONTROL_NOT_PAGEABLE], pagedControlID)); } return(ret); } // No ID set, try to find a container that's pageable container = NamingContainer; while (container != page) { if (container == null) { throw new InvalidOperationException(_exceptionMessages [NO_NAMING_CONTAINER]); } ret = container as IPageableItemContainer; if (ret != null) { return(ret); } container = container.NamingContainer; } return(ret); }