protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { int rows = base.CreateChildControls(dataSource, dataBinding); // no data rows created, create empty table if enabled if (rows == 0 && this.ShowWhenEmpty) { // create the table Table table = new Table(); FormViewRow fr = new FormViewRow(0,DataControlRowType.DataRow,DataControlRowState.Normal); TableCell tc = new TableCell(); this.ItemTemplate.InstantiateIn(tc); fr.Controls.Add(tc); table.Controls.Add(fr); this.Controls.Clear(); this.Controls.Add(table); } return rows; }
protected override int CreateChildControls (IEnumerable data, bool dataBinding) { PagedDataSource dataSource = new PagedDataSource (); dataSource.DataSource = CurrentMode != FormViewMode.Insert ? data : null; dataSource.AllowPaging = AllowPaging; dataSource.PageSize = 1; dataSource.CurrentPageIndex = PageIndex; if (dataBinding && CurrentMode != FormViewMode.Insert) { DataSourceView view = GetData (); if (view != null && view.CanPage) { dataSource.AllowServerPaging = true; if (SelectArguments.RetrieveTotalRowCount) dataSource.VirtualCount = SelectArguments.TotalRowCount; } } PagerSettings pagerSettings = PagerSettings; bool showPager = AllowPaging && pagerSettings.Visible && (dataSource.PageCount > 1); Controls.Clear (); table = CreateTable (); Controls.Add (table); headerRow = null; footerRow = null; topPagerRow = null; bottomPagerRow = null; // Gets the current data item if (AllowPaging) { PageCount = dataSource.DataSourceCount; if (PageIndex >= PageCount && PageCount > 0) pageIndex = dataSource.CurrentPageIndex = PageCount - 1; if (dataSource.DataSource != null) { IEnumerator e = dataSource.GetEnumerator (); if (e.MoveNext ()) dataItem = e.Current; } } else { int page = 0; object lastItem = null; if (dataSource.DataSource != null) { IEnumerator e = dataSource.GetEnumerator (); for (; e.MoveNext (); page++) { lastItem = e.Current; if (page == PageIndex) dataItem = e.Current; } } PageCount = page; if (PageIndex >= PageCount && PageCount > 0) { pageIndex = PageCount - 1; dataItem = lastItem; } } // Main table creation bool emptyRow = PageCount == 0 && CurrentMode != FormViewMode.Insert; if (!emptyRow) { headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal); InitializeRow (headerRow); table.Rows.Add (headerRow); } if (showPager && pagerSettings.Position == PagerPosition.Top || pagerSettings.Position == PagerPosition.TopAndBottom) { topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (topPagerRow, dataSource); table.Rows.Add (topPagerRow); } if (PageCount > 0) { DataControlRowState rstate = GetRowState (); itemRow = CreateRow (0, DataControlRowType.DataRow, rstate); InitializeRow (itemRow); table.Rows.Add (itemRow); } else { switch (CurrentMode) { case FormViewMode.Edit: itemRow = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Edit); break; case FormViewMode.Insert: itemRow = CreateRow (-1, DataControlRowType.DataRow, DataControlRowState.Insert); break; default: itemRow = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); break; } InitializeRow (itemRow); table.Rows.Add (itemRow); } if (!emptyRow) { footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal); InitializeRow (footerRow); table.Rows.Add (footerRow); } if (showPager && pagerSettings.Position == PagerPosition.Bottom || pagerSettings.Position == PagerPosition.TopAndBottom) { bottomPagerRow = CreateRow (0, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (bottomPagerRow, dataSource); table.Rows.Add (bottomPagerRow); } OnItemCreated (EventArgs.Empty); if (dataBinding) DataBind (false); return PageCount; }
protected virtual void InitializeRow (FormViewRow row) { TableCell cell = new TableCell (); if (row.RowType == DataControlRowType.DataRow) { if ((row.RowState & DataControlRowState.Edit) != 0) { if (editItemTemplate != null) editItemTemplate.InstantiateIn (cell); else row.Visible = false; } else if ((row.RowState & DataControlRowState.Insert) != 0) { if (insertItemTemplate != null) insertItemTemplate.InstantiateIn (cell); else row.Visible = false; } else if (itemTemplate != null) itemTemplate.InstantiateIn (cell); else row.Visible = false; } else if (row.RowType == DataControlRowType.EmptyDataRow) { if (emptyDataTemplate != null) emptyDataTemplate.InstantiateIn (cell); else if (!String.IsNullOrEmpty (EmptyDataText)) cell.Text = EmptyDataText; else row.Visible = false; } else if (row.RowType == DataControlRowType.Footer) { if (footerTemplate != null) footerTemplate.InstantiateIn (cell); else if (!String.IsNullOrEmpty (FooterText)) cell.Text = FooterText; else row.Visible = false; } else if (row.RowType == DataControlRowType.Header) { if (headerTemplate != null) headerTemplate.InstantiateIn (cell); else if (!String.IsNullOrEmpty (HeaderText)) cell.Text = HeaderText; else row.Visible = false; } cell.ColumnSpan = 2; row.Cells.Add (cell); row.RenderJustCellContents = !RenderOuterTable; }
protected virtual void InitializePager (FormViewRow row, PagedDataSource dataSource) { TableCell cell = new TableCell (); cell.ColumnSpan = 2; if (pagerTemplate != null) pagerTemplate.InstantiateIn (cell); else cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount)); row.Cells.Add (cell); }
protected override void InitializeRow(FormViewRow row) { base.InitializeRow(row); if (!DesignMode && row.RowType == DataControlRowType.DataRow) { object obj = this.GetObjByID(this.DataSourceID); if (obj != null && obj is WebDataSource) { WebDataSource wds = (WebDataSource)obj; if (wds.InnerDataSet != null) { DataTable tab = wds.View.Table; AllCtrls.Clear(); GetAllCtrls(this.Controls); foreach (Control ctrl in AllCtrls) { if (ctrl is WebExpressionControl) { WebExpressionControl expCtrl = (WebExpressionControl)ctrl; if (expCtrl.Expression != null && expCtrl.Expression != "") { if (!tab.Columns.Contains(expCtrl.Expression)) { DataColumn col = new DataColumn(expCtrl.Expression, typeof(decimal), expCtrl.Expression); tab.Columns.Add(col); } } } } } } } }
protected virtual new void InitializeRow(FormViewRow row) { }
protected virtual new void InitializePager(FormViewRow row, PagedDataSource pagedDataSource) { }
protected override int CreateChildControls (IEnumerable data, bool dataBinding) { PagedDataSource dataSource; if (dataBinding) { DataSourceView view = GetData (); dataSource = new PagedDataSource (); dataSource.DataSource = data; if (AllowPaging) { dataSource.AllowPaging = true; dataSource.PageSize = 1; dataSource.CurrentPageIndex = PageIndex; if (view.CanPage) { dataSource.AllowServerPaging = true; if (view.CanRetrieveTotalRowCount) dataSource.VirtualCount = SelectArguments.TotalRowCount; else { dataSource.DataSourceView = view; dataSource.DataSourceSelectArguments = SelectArguments; dataSource.SetItemCountFromPageIndex (PageIndex + PagerSettings.PageButtonCount); } } } pageCount = dataSource.PageCount; } else { dataSource = new PagedDataSource (); dataSource.DataSource = data; if (AllowPaging) { dataSource.AllowPaging = true; dataSource.PageSize = 1; dataSource.CurrentPageIndex = PageIndex; } } bool showPager = AllowPaging && (PageCount > 1); dataSourceCount = dataSource.Count; Controls.Clear (); table = CreateTable (); Controls.Add (table); if (!Page.IsPostBack) currentMode = DefaultMode; // Gets the current data item IEnumerator e = dataSource.GetEnumerator (); if (e.MoveNext ()) dataItem = e.Current; else dataItem = null; // Main table creation if (HeaderText.Length != 0 || headerTemplate != null) { headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal); InitializeRow (headerRow); table.Rows.Add (headerRow); } if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) { topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (topPagerRow, dataSource); table.Rows.Add (topPagerRow); } if (dataSourceCount > 0) { DataControlRowState rstate = GetRowState (); itemRow = CreateRow (0, DataControlRowType.DataRow, rstate); InitializeRow (itemRow); table.Rows.Add (itemRow); if (!dataBinding) { if (CurrentMode == FormViewMode.Edit) oldEditValues = new DataKey (new OrderedDictionary ()); key = new DataKey (new OrderedDictionary (), DataKeyNames); } } else { itemRow = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); table.Rows.Add (itemRow); InitializeRow (itemRow); } if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) { bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (bottomPagerRow, dataSource); table.Rows.Add (bottomPagerRow); } if (FooterText.Length != 0 || footerTemplate != null) { footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal); InitializeRow (footerRow); table.Rows.Add (footerRow); } if (dataBinding) DataBind (false); return dataSource.DataSourceCount; }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> protected virtual void InitializeRow(FormViewRow row) { TableCellCollection cells = row.Cells; TableCell contentCell = new TableCell(); ITemplate contentTemplate = _itemTemplate; int itemIndex = row.ItemIndex; DataControlRowState rowState = row.RowState; switch (row.RowType) { case DataControlRowType.DataRow: contentCell.ColumnSpan = 2; if (((rowState & DataControlRowState.Edit) != 0) && _editItemTemplate != null) { contentTemplate = _editItemTemplate; } if ((rowState & DataControlRowState.Insert) != 0) { if (_insertItemTemplate != null) { contentTemplate = _insertItemTemplate; } else { contentTemplate = _editItemTemplate; } } break; case DataControlRowType.Header: contentTemplate = _headerTemplate; contentCell.ColumnSpan = 2; string headerText = HeaderText; if (_headerTemplate == null && headerText.Length > 0) { contentCell.Text = headerText; } break; case DataControlRowType.Footer: contentTemplate = _footerTemplate; contentCell.ColumnSpan = 2; string footerText = FooterText; if (_footerTemplate == null && footerText.Length > 0) { contentCell.Text = footerText; } break; case DataControlRowType.EmptyDataRow: contentTemplate = _emptyDataTemplate; string emptyDataText = EmptyDataText; if (_emptyDataTemplate == null && emptyDataText.Length > 0) { contentCell.Text = emptyDataText; } break; } if (contentTemplate != null) { contentTemplate.InstantiateIn(contentCell); } cells.Add(contentCell); }
/// <devdoc> /// <para> /// Creates a FormViewRow that contains the paging UI. /// The paging UI is a navigation bar that is a built into a single TableCell that /// spans across all fields of the FormView. /// </para> /// </devdoc> protected virtual void InitializePager(FormViewRow row, PagedDataSource pagedDataSource) { TableCell cell = new TableCell(); PagerSettings pagerSettings = PagerSettings; if (_pagerTemplate != null) { _pagerTemplate.InstantiateIn(cell); } else { PagerTable pagerTable = new PagerTable(); TableRow pagerTableRow = new TableRow(); cell.Controls.Add(pagerTable); pagerTable.Rows.Add(pagerTableRow); switch (pagerSettings.Mode) { case PagerButtons.NextPrevious: CreateNextPrevPager(pagerTableRow, pagedDataSource, false); break; case PagerButtons.Numeric: CreateNumericPager(pagerTableRow, pagedDataSource, false); break; case PagerButtons.NextPreviousFirstLast: CreateNextPrevPager(pagerTableRow, pagedDataSource, true); break; case PagerButtons.NumericFirstLast: CreateNumericPager(pagerTableRow, pagedDataSource, true); break; } } cell.ColumnSpan = 2; row.Cells.Add(cell); }
/// <devdoc> /// <para>Creates the control hierarchy that is used to render the FormView. /// This is called whenever a control hierarchy is needed and the /// ChildControlsCreated property is false. /// The implementation assumes that all the children in the controls /// collection have already been cleared.</para> /// </devdoc> protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding) { PagedDataSource pagedDataSource = null; int itemIndex = PageIndex; bool allowPaging = AllowPaging; int itemCount = 0; FormViewMode mode = Mode; // if we're in design mode, PageIndex doesn't return -1 if (DesignMode && mode == FormViewMode.Insert) { itemIndex = -1; } if (dataBinding) { DataSourceView view = GetData(); DataSourceSelectArguments arguments = SelectArguments; if (view == null) { throw new HttpException(SR.GetString(SR.DataBoundControl_NullView, ID)); } if (mode != FormViewMode.Insert) { if (allowPaging && !view.CanPage) { if (dataSource != null && !(dataSource is ICollection)) { arguments.StartRowIndex = itemIndex; arguments.MaximumRows = 1; // This should throw an exception saying the data source can't page. // We do this because the data source can provide a better error message than we can. view.Select(arguments, SelectCallback); } } if (_useServerPaging) { if (view.CanRetrieveTotalRowCount) { pagedDataSource = CreateServerPagedDataSource(arguments.TotalRowCount); } else { ICollection dataSourceCollection = dataSource as ICollection; if (dataSourceCollection == null) { throw new HttpException(SR.GetString(SR.DataBoundControl_NeedICollectionOrTotalRowCount, GetType().Name)); } pagedDataSource = CreateServerPagedDataSource(checked(PageIndex + dataSourceCollection.Count)); } } else { pagedDataSource = CreatePagedDataSource(); } } } else { pagedDataSource = CreatePagedDataSource(); } if (mode != FormViewMode.Insert) { pagedDataSource.DataSource = dataSource; } IEnumerator dataSourceEnumerator = null; OrderedDictionary keyTable = KeyTable; if (dataBinding == false) { dataSourceEnumerator = dataSource.GetEnumerator(); ICollection collection = dataSource as ICollection; if (collection == null) { throw new HttpException(SR.GetString(SR.DataControls_DataSourceMustBeCollectionWhenNotDataBinding)); } itemCount = collection.Count; } else { keyTable.Clear(); if (dataSource != null) { if (mode != FormViewMode.Insert) { ICollection collection = dataSource as ICollection; if ((collection == null) && (pagedDataSource.IsPagingEnabled && !pagedDataSource.IsServerPagingEnabled)) { throw new HttpException(SR.GetString(SR.FormView_DataSourceMustBeCollection, ID)); } if (pagedDataSource.IsPagingEnabled) { itemCount = pagedDataSource.DataSourceCount; } else if (collection != null) { itemCount = collection.Count; } } dataSourceEnumerator = dataSource.GetEnumerator(); } } Table table = CreateTable(); TableRowCollection rows = table.Rows; bool moveNextSucceeded = false; object lastItem = null; Controls.Add(table); if (dataSourceEnumerator != null) { moveNextSucceeded = dataSourceEnumerator.MoveNext(); // goto the first item } // if there are no items, only add the tablerow if there's a null template or null text if (!moveNextSucceeded && mode != FormViewMode.Insert) { if (EmptyDataText.Length > 0 || _emptyDataTemplate != null) { _row = CreateRow(0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, rows, null); } itemCount = 0; } else { int currentItemIndex = 0; if (!_useServerPaging) { // skip over the first records that are before the page we're showing for (; currentItemIndex < itemIndex; currentItemIndex++) { lastItem = dataSourceEnumerator.Current; moveNextSucceeded = dataSourceEnumerator.MoveNext(); if (!moveNextSucceeded) { _pageIndex = currentItemIndex; pagedDataSource.CurrentPageIndex = currentItemIndex; itemIndex = currentItemIndex; break; // never throw if the PageIndex is out of range: just fix up PageIndex and goto the last item. } } } if (moveNextSucceeded) { _dataItem = dataSourceEnumerator.Current; } else { _dataItem = lastItem; // if we broke out of the above loop, the current item will be invalid } // If we're not using server paging and this isn't a collection, or server paging doesn't return a page count, our _pageCount isn't accurate. // Loop through the rest of the enumeration to figure out how many items are in it. if ((!_useServerPaging && !(dataSource is ICollection)) || (_useServerPaging && itemCount < 0)) { itemCount = currentItemIndex; while (moveNextSucceeded) { itemCount++; moveNextSucceeded = dataSourceEnumerator.MoveNext(); } } _dataItemIndex = currentItemIndex; bool singlePage = itemCount <= 1 && !_useServerPaging; // hide pagers if there's only one item if (allowPaging && PagerSettings.Visible && _pagerSettings.IsPagerOnTop && mode != FormViewMode.Insert && !singlePage) { // top pager _topPagerRow = CreateRow(itemIndex, DataControlRowType.Pager, DataControlRowState.Normal, rows, pagedDataSource); } _headerRow = CreateRow(itemIndex, DataControlRowType.Header, DataControlRowState.Normal, rows, null); if (_headerTemplate == null && HeaderText.Length == 0) { _headerRow.Visible = false; } _row = CreateDataRow(dataBinding, rows, _dataItem); if (itemIndex >= 0) { string[] keyFields = DataKeyNamesInternal; if (dataBinding && (keyFields.Length != 0)) { foreach (string keyName in keyFields) { object keyValue = DataBinder.GetPropertyValue(_dataItem, keyName); keyTable.Add(keyName, keyValue); } _dataKey = new DataKey(keyTable); } } _footerRow = CreateRow(itemIndex, DataControlRowType.Footer, DataControlRowState.Normal, rows, null); if (_footerTemplate == null && FooterText.Length == 0) { _footerRow.Visible = false; } if (allowPaging && PagerSettings.Visible && _pagerSettings.IsPagerOnBottom && mode != FormViewMode.Insert && !singlePage) { // bottom pager _bottomPagerRow = CreateRow(itemIndex, DataControlRowType.Pager, DataControlRowState.Normal, rows, pagedDataSource); } } _pageCount = itemCount; OnItemCreated(EventArgs.Empty); if (dataBinding) { DataBind(false); } return itemCount; }
protected virtual void InitializeRow (FormViewRow row) { TableCell cell = new TableCell (); if (row.RowType == DataControlRowType.DataRow) { if ((row.RowState & DataControlRowState.Edit) != 0) { if (editItemTemplate != null) editItemTemplate.InstantiateIn (cell); } else if ((row.RowState & DataControlRowState.Insert) != 0) { if (insertItemTemplate != null) insertItemTemplate.InstantiateIn (cell); } else if (itemTemplate != null) itemTemplate.InstantiateIn (cell); } else if (row.RowType == DataControlRowType.EmptyDataRow) { if (emptyDataTemplate != null) emptyDataTemplate.InstantiateIn (cell); else cell.Text = EmptyDataText; } else if (row.RowType == DataControlRowType.Footer) { if (footerTemplate != null) footerTemplate.InstantiateIn (cell); else cell.Text = FooterText; } else if (row.RowType == DataControlRowType.Header) { if (headerTemplate != null) headerTemplate.InstantiateIn (cell); else cell.Text = HeaderText; } row.Cells.Add (cell); }
protected override void InitializePager (FormViewRow row, PagedDataSource pageData) { base.InitializePager (row, pageData); isInitializePager = true; }
public void DoInitializeRow (FormViewRow row) { InitializeRow (row); }
protected virtual FormViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState) { FormViewRow row = new FormViewRow (rowIndex, rowType, rowState); OnItemCreated (EventArgs.Empty); return row; }