예제 #1
0
		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 = PageSize;
					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 = PageSize;
					dataSource.CurrentPageIndex = PageIndex;
				}
			}

			bool showPager = AllowPaging && (PageCount > 1);
			
			Controls.Clear ();
			table = CreateChildTable ();
			Controls.Add (table);
				
			ArrayList list = new ArrayList ();
			ArrayList keyList = new ArrayList ();
			
			// Creates the set of fields to show
			
			ICollection fieldCollection = CreateColumns (dataSource, dataBinding);
			DataControlField[] fields = new DataControlField [fieldCollection.Count];
			fieldCollection.CopyTo (fields, 0);

			foreach (DataControlField field in fields) {
				field.Initialize (AllowSorting, this);
				if (EnableSortingAndPagingCallbacks)
					field.ValidateSupportsCallback ();
			}

			// Main table creation
			
			if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
				topPagerRow = CreatePagerRow (fields.Length, dataSource);
				table.Rows.Add (topPagerRow);
			}

			if (ShowHeader) {
				headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
				table.Rows.Add (headerRow);
				InitializeRow (headerRow, fields);
			}
			
			foreach (object obj in dataSource) {
				DataControlRowState rstate = GetRowState (list.Count);
				GridViewRow row = CreateRow (list.Count, list.Count, DataControlRowType.DataRow, rstate);
				row.DataItem = obj;
				list.Add (row);
				table.Rows.Add (row);
				InitializeRow (row, fields);
				if (dataBinding) {
//					row.DataBind ();
					OnRowDataBound (new GridViewRowEventArgs (row));
					if (EditIndex == row.RowIndex)
						oldEditValues = new DataKey (GetRowValues (row, false, true));
					keyList.Add (new DataKey (CreateRowDataKey (row), DataKeyNames));
				} else {
					if (EditIndex == row.RowIndex)
						oldEditValues = new DataKey (new OrderedDictionary ());
					keyList.Add (new DataKey (new OrderedDictionary (), DataKeyNames));
				}

				if (list.Count >= PageSize)
					break;
			}
			
			if (list.Count == 0)
				table.Rows.Add (CreateEmptyrRow (fields.Length));

			if (ShowFooter) {
				footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
				table.Rows.Add (footerRow);
				InitializeRow (footerRow, fields);
			}

			if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
				bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
				table.Rows.Add (bottomPagerRow);
			}

			rows = new GridViewRowCollection (list);
			keys = new DataKeyArray (keyList);
			
			if (dataBinding)
				DataBind (false);

			return dataSource.DataSourceCount;
		}
예제 #2
0
		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);
			
			Controls.Clear ();
			table = CreateTable ();
			Controls.Add (table);
				
			ArrayList list = new ArrayList ();

			if (!Page.IsPostBack)
				currentMode = DefaultMode;

			
			// Gets the current data item
			
			IEnumerator e = dataSource.GetEnumerator (); 
			if (e.MoveNext ())
				dataItem = e.Current;
			else
				dataItem = null;
			
			// Creates the set of fields to show
			
			ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding);
			DataControlField[] fields = new DataControlField [fieldCollection.Count];
			fieldCollection.CopyTo (fields, 0);

			foreach (DataControlField field in fields) {
				field.Initialize (false, this);
				if (EnablePagingCallbacks)
					field.ValidateSupportsCallback ();
			}

			// Main table creation
			
			if (HeaderText.Length != 0 || headerTemplate != null) {
				headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal);
				DataControlFieldCell cell = new DataControlFieldCell (null);
				cell.ColumnSpan = 2;
				if (headerTemplate != null)
					headerTemplate.InstantiateIn (cell);
				else
					cell.Text = HeaderText;
				headerRow.Cells.Add (cell);
				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 (dataSource.Count > 0) {
				foreach (DataControlField field in fields) {
					DataControlRowState rstate = GetRowState (list.Count);
					DetailsViewRow row = CreateRow (list.Count, DataControlRowType.DataRow, rstate);
					InitializeRow (row, field);
					table.Rows.Add (row);
					list.Add (row);

					if (commandField == field)
						commandRow = row;
				}
				if (!dataBinding) {
					if (CurrentMode == DetailsViewMode.Edit)
						oldEditValues = new DataKey (new OrderedDictionary ());
					key = new DataKey (new OrderedDictionary (), DataKeyNames);
				}
			} else {
				table.Rows.Add (CreateEmptyrRow ());
			}

			rows = new DetailsViewRowCollection (list);
			
			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);
				DataControlFieldCell cell = new DataControlFieldCell (null);
				cell.ColumnSpan = 2;
				if (footerTemplate != null)
					footerTemplate.InstantiateIn (cell);
				else
					cell.Text = FooterText;
				footerRow.Cells.Add (cell);
				table.Rows.Add (footerRow);
			}
			
			if (dataBinding)
				DataBind (false);
			
			return dataSource.DataSourceCount;
		}
예제 #3
0
		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;
		}