Example #1
0
 protected virtual new void InitializeRow(DetailsViewRow row, DataControlField field)
 {
     Contract.Requires(row != null);
     Contract.Requires(this.EmptyDataText != null);
     Contract.Requires(field != null);
     Contract.Requires(row.Cells != null);
     Contract.Requires(this.FooterText != null);
     Contract.Requires(this.HeaderText != null);
 }
		public void DetailsViewRowCollection_CopyTo ()
		{
			DetailsViewRow[] rows = new DetailsViewRow[6];
			ArrayList myRows = new ArrayList ();
			myRows.Add (new DetailsViewRow (0, DataControlRowType.DataRow, DataControlRowState.Insert));
			myRows.Add (new DetailsViewRow (1, DataControlRowType.Footer, DataControlRowState.Edit));
			myRows.Add (new DetailsViewRow (2, DataControlRowType.Header, DataControlRowState.Normal)); 			
			DetailsViewRowCollection coll = new DetailsViewRowCollection (myRows);						
			coll.CopyTo(rows,0);			
			Assert.AreEqual (6, rows.Length, "CopyTo1");
			Assert.AreEqual (0, rows[0].RowIndex, "CopyTo2");
			Assert.AreEqual (DataControlRowType.Footer , rows[1].RowType , "CopyTo3");
			Assert.AreEqual (DataControlRowState.Normal, rows[2].RowState, "CopyTo4");
			Assert.AreEqual (2, rows[2].RowIndex, "CopyTo5");
			Assert.AreEqual (null, rows[3], "CopyTo6");
			
		}
 protected virtual new void InitializeRow (DetailsViewRow row, DataControlField field)
 {
   Contract.Requires (row != null);
   Contract.Requires (this.EmptyDataText != null);
   Contract.Requires (field != null);
   Contract.Requires (row.Cells != null);
   Contract.Requires (this.FooterText != null);
   Contract.Requires (this.HeaderText != null);
 }
 /// <devdoc>
 /// <para>Copies the contents of the entire collection into an <see cref='System.Array' qualify='true'/> appending 
 ///    at the specified index of the <see cref='System.Array' qualify='true'/>.</para>
 /// </devdoc>
 public void CopyTo(DetailsViewRow[] array, int index) {
     ((ICollection)this).CopyTo(array, index);
 }
Example #5
0
 protected virtual new void InitializePager(DetailsViewRow row, PagedDataSource pagedDataSource)
 {
     Contract.Requires(this.PagerSettings != null);
     Contract.Requires(row != null);
     Contract.Requires(row.Cells != null);
 }
Example #6
0
        /// <devdoc>
        /// <para>
        /// Creates a DetailsViewRow 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 DetailsView.
        /// </para>
        /// </devdoc>
        protected virtual void InitializePager(DetailsViewRow 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);
        }
		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;
		}
		protected virtual void InitializeRow (DetailsViewRow row, DataControlField field)
		{
			DataControlFieldCell cell;
			
			if (field.ShowHeader) {
				cell = new DataControlFieldCell (field);
				row.Cells.Add (cell);
				field.InitializeCell (cell, DataControlCellType.Header, row.RowState, row.RowIndex);
			}
			
			cell = new DataControlFieldCell (field);
			if (!field.ShowHeader)
				cell.ColumnSpan = 2;
			row.Cells.Add (cell);
			field.InitializeCell (cell, DataControlCellType.DataCell, row.RowState, row.RowIndex);
		}
Example #9
0
 protected override void InitializePager(DetailsViewRow row, PagedDataSource pagedDataSource)
 {
     base.InitializePager(row, pagedDataSource);
     if (row.RowType == DataControlRowType.Pager && CreateInnerNavigator)
     {
         // add WebNavigator for Add and Query
         #region Add Navigator
         InitNavControls(row);
         #endregion
     }
 }
 protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
 {
     PagedDataSource pagedDataSource = null;
     int pageIndex = this.PageIndex;
     bool allowPaging = this.AllowPaging;
     int count = 0;
     DetailsViewMode mode = this.Mode;
     if (base.DesignMode && (mode == DetailsViewMode.Insert))
     {
         pageIndex = -1;
     }
     if (dataBinding)
     {
         DataSourceView data = this.GetData();
         DataSourceSelectArguments selectArguments = base.SelectArguments;
         if (data == null)
         {
             throw new HttpException(System.Web.SR.GetString("DataBoundControl_NullView", new object[] { this.ID }));
         }
         if (mode != DetailsViewMode.Insert)
         {
             if ((allowPaging && !data.CanPage) && ((dataSource != null) && !(dataSource is ICollection)))
             {
                 selectArguments.StartRowIndex = pageIndex;
                 selectArguments.MaximumRows = 1;
                 data.Select(selectArguments, new DataSourceViewSelectCallback(this.SelectCallback));
             }
             if (this._useServerPaging)
             {
                 if (data.CanRetrieveTotalRowCount)
                 {
                     pagedDataSource = this.CreateServerPagedDataSource(selectArguments.TotalRowCount);
                 }
                 else
                 {
                     ICollection is2 = dataSource as ICollection;
                     if (is2 == null)
                     {
                         throw new HttpException(System.Web.SR.GetString("DataBoundControl_NeedICollectionOrTotalRowCount", new object[] { base.GetType().Name }));
                     }
                     pagedDataSource = this.CreateServerPagedDataSource(this.PageIndex + is2.Count);
                 }
             }
             else
             {
                 pagedDataSource = this.CreatePagedDataSource();
             }
         }
     }
     else
     {
         pagedDataSource = this.CreatePagedDataSource();
     }
     if (mode != DetailsViewMode.Insert)
     {
         pagedDataSource.DataSource = dataSource;
     }
     IEnumerator enumerator = null;
     OrderedDictionary keyTable = this.KeyTable;
     this._rowsArray = new ArrayList();
     this._rowsCollection = null;
     if (!dataBinding)
     {
         enumerator = dataSource.GetEnumerator();
         ICollection is3 = dataSource as ICollection;
         if (is3 == null)
         {
             throw new HttpException(System.Web.SR.GetString("DataControls_DataSourceMustBeCollectionWhenNotDataBinding"));
         }
         count = is3.Count;
     }
     else
     {
         keyTable.Clear();
         if (dataSource != null)
         {
             if (mode != DetailsViewMode.Insert)
             {
                 ICollection is4 = dataSource as ICollection;
                 if (((is4 == null) && pagedDataSource.IsPagingEnabled) && !pagedDataSource.IsServerPagingEnabled)
                 {
                     throw new HttpException(System.Web.SR.GetString("DetailsView_DataSourceMustBeCollection", new object[] { this.ID }));
                 }
                 if (pagedDataSource.IsPagingEnabled)
                 {
                     count = pagedDataSource.DataSourceCount;
                 }
                 else if (is4 != null)
                 {
                     count = is4.Count;
                 }
             }
             enumerator = dataSource.GetEnumerator();
         }
     }
     Table child = this.CreateTable();
     TableRowCollection rows = child.Rows;
     bool flag2 = false;
     object current = null;
     this.Controls.Add(child);
     if (enumerator != null)
     {
         flag2 = enumerator.MoveNext();
     }
     if (!flag2 && (mode != DetailsViewMode.Insert))
     {
         if ((pageIndex >= 0) || this.AutoGenerateRows)
         {
             if ((this.EmptyDataText.Length > 0) || (this._emptyDataTemplate != null))
             {
                 this._rowsArray.Add(this.CreateRow(0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, null, rows, null));
             }
             count = 0;
         }
     }
     else
     {
         int num3 = 0;
         if (!this._useServerPaging)
         {
             while (num3 < pageIndex)
             {
                 current = enumerator.Current;
                 flag2 = enumerator.MoveNext();
                 if (!flag2)
                 {
                     this._pageIndex = num3;
                     pagedDataSource.CurrentPageIndex = num3;
                     pageIndex = num3;
                     break;
                 }
                 num3++;
             }
         }
         if (flag2)
         {
             this._dataItem = enumerator.Current;
         }
         else
         {
             this._dataItem = current;
         }
         if ((!this._useServerPaging && !(dataSource is ICollection)) || (this._useServerPaging && (count < 0)))
         {
             count = num3;
             while (flag2)
             {
                 count++;
                 flag2 = enumerator.MoveNext();
             }
         }
         this._dataItemIndex = num3;
         bool flag3 = (count <= 1) && !this._useServerPaging;
         if (((allowPaging && this.PagerSettings.Visible) && (this._pagerSettings.IsPagerOnTop && !flag3)) && (mode != DetailsViewMode.Insert))
         {
             this._topPagerRow = this.CreateRow(-1, DataControlRowType.Pager, DataControlRowState.Normal, null, rows, pagedDataSource);
         }
         this._headerRow = this.CreateRow(-1, DataControlRowType.Header, DataControlRowState.Normal, null, rows, null);
         if ((this._headerTemplate == null) && (this.HeaderText.Length == 0))
         {
             this._headerRow.Visible = false;
         }
         this._rowsArray.AddRange(this.CreateDataRows(dataBinding, rows, this._dataItem));
         if (pageIndex >= 0)
         {
             string[] dataKeyNamesInternal = this.DataKeyNamesInternal;
             if (dataBinding && (dataKeyNamesInternal.Length != 0))
             {
                 foreach (string str in dataKeyNamesInternal)
                 {
                     object propertyValue = DataBinder.GetPropertyValue(this._dataItem, str);
                     keyTable.Add(str, propertyValue);
                 }
                 this._dataKey = new System.Web.UI.WebControls.DataKey(keyTable);
             }
         }
         this._footerRow = this.CreateRow(-1, DataControlRowType.Footer, DataControlRowState.Normal, null, rows, null);
         if ((this._footerTemplate == null) && (this.FooterText.Length == 0))
         {
             this._footerRow.Visible = false;
         }
         if (((allowPaging && this.PagerSettings.Visible) && (this._pagerSettings.IsPagerOnBottom && !flag3)) && (mode != DetailsViewMode.Insert))
         {
             this._bottomPagerRow = this.CreateRow(-1, DataControlRowType.Pager, DataControlRowState.Normal, null, rows, pagedDataSource);
         }
     }
     this._pageCount = count;
     this.OnItemCreated(EventArgs.Empty);
     if (dataBinding)
     {
         this.DataBind(false);
     }
     return count;
 }
 protected virtual void InitializeRow(DetailsViewRow row, DataControlField field)
 {
     TableCellCollection cells = row.Cells;
     DataControlFieldCell cell = new DataControlFieldCell(field);
     ITemplate template = null;
     int dataItemIndex = this.DataItemIndex;
     DataControlRowState rowState = row.RowState;
     switch (row.RowType)
     {
         case DataControlRowType.Header:
         {
             template = this._headerTemplate;
             cell.ColumnSpan = 2;
             string headerText = this.HeaderText;
             if ((this._headerTemplate == null) && (headerText.Length > 0))
             {
                 cell.Text = headerText;
             }
             goto Label_0116;
         }
         case DataControlRowType.Footer:
         {
             template = this._footerTemplate;
             cell.ColumnSpan = 2;
             string footerText = this.FooterText;
             if ((this._footerTemplate == null) && (footerText.Length > 0))
             {
                 cell.Text = footerText;
             }
             goto Label_0116;
         }
         case DataControlRowType.DataRow:
         {
             if (!field.ShowHeader)
             {
                 cell.ColumnSpan = 2;
                 break;
             }
             DataControlFieldCell cell2 = new DataControlFieldCell(field);
             field.InitializeCell(cell2, DataControlCellType.Header, rowState, dataItemIndex);
             cells.Add(cell2);
             break;
         }
         case DataControlRowType.EmptyDataRow:
         {
             template = this._emptyDataTemplate;
             string emptyDataText = this.EmptyDataText;
             if ((this._emptyDataTemplate == null) && (emptyDataText.Length > 0))
             {
                 cell.Text = emptyDataText;
             }
             goto Label_0116;
         }
         default:
             goto Label_0116;
     }
     field.InitializeCell(cell, DataControlCellType.DataCell, rowState, dataItemIndex);
 Label_0116:
     if (template != null)
     {
         template.InstantiateIn(cell);
     }
     cells.Add(cell);
 }
        protected virtual void InitializePager(DetailsViewRow row, PagedDataSource pagedDataSource)
        {
            TableCell container = new TableCell();
            System.Web.UI.WebControls.PagerSettings pagerSettings = this.PagerSettings;
            if (this._pagerTemplate != null)
            {
                this._pagerTemplate.InstantiateIn(container);
            }
            else
            {
                PagerTable child = new PagerTable();
                TableRow row2 = new TableRow();
                container.Controls.Add(child);
                child.Rows.Add(row2);
                switch (pagerSettings.Mode)
                {
                    case PagerButtons.NextPrevious:
                        this.CreateNextPrevPager(row2, pagedDataSource, false);
                        break;

                    case PagerButtons.Numeric:
                        this.CreateNumericPager(row2, pagedDataSource, false);
                        break;

                    case PagerButtons.NextPreviousFirstLast:
                        this.CreateNextPrevPager(row2, pagedDataSource, true);
                        break;

                    case PagerButtons.NumericFirstLast:
                        this.CreateNumericPager(row2, pagedDataSource, true);
                        break;
                }
            }
            container.ColumnSpan = 2;
            row.Cells.Add(container);
        }
 protected virtual new void InitializeRow(DetailsViewRow row, DataControlField field)
 {
 }
 protected virtual new void InitializePager(DetailsViewRow row, PagedDataSource pagedDataSource)
 {
 }
		protected virtual void InitializeRow (DetailsViewRow row, DataControlField field)
		{
			if (!field.Visible) {
				row.Visible = false;
				return;
			}
			
			row.ContainingField = field;
			DataControlFieldCell cell;
			
			if (field.ShowHeader) {
				cell = new DataControlFieldCell (field);
				row.Cells.Add (cell);
				field.InitializeCell (cell, DataControlCellType.Header, row.RowState, row.RowIndex);
			}
			
			cell = new DataControlFieldCell (field);
			if (!field.ShowHeader)
				cell.ColumnSpan = 2;
			row.Cells.Add (cell);
			field.InitializeCell (cell, DataControlCellType.DataCell, row.RowState, row.RowIndex);

			if (CurrentMode == DetailsViewMode.Insert && !field.InsertVisible)
				row.Visible = false;
		}
		protected virtual void InitializePager (DetailsViewRow 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);
		}
Example #17
0
 protected override void InitializeRow(DetailsViewRow row, DataControlField field)
 {
     base.InitializeRow(row, field);
     object obj = this.GetObjByID(this.DataSourceID);
     WebDataSource wds = null;
     if (obj != null)
     {
         wds = (WebDataSource)obj;
     }
     if (this.Site == null)
     {
         if (row.RowType == DataControlRowType.DataRow)
         {
             if (field is ExpressionField)
             {
                 ExpressionField expField = (ExpressionField)field;
                 Control ctrl = row.FindControl("ExpressionLabel" + expField.Expression + this.PageIndex);
                 if (ctrl != null && ctrl is Label)
                 {
                     string strExpression = ((Label)ctrl).Text;
                     if (obj is WebDataSource)
                     {
                         DataTable tab = wds.View.Table;
                         int i = this.DataItemIndex;
                         for (int j = 0; j <= i; j++)
                         {
                             if (tab.Rows[j].RowState == DataRowState.Deleted)
                             {
                                 i++;
                             }
                         }
                         ((Label)ctrl).Text = tab.Rows[i][strExpression].ToString();
                     }
                 }
             }
             if (field is CommandField || field is TemplateField)
             {
                 foreach (TableCell cell in row.Cells)
                 {
                     foreach (Control ctrl in cell.Controls)
                     {
                         if (ctrl is IButtonControl)
                         {
                             IButtonControl btn = (IButtonControl)ctrl;
                             if (btn.CommandName == "Edit")
                             {
                                 if (wds != null && !wds.AllowUpdate)
                                 {
                                     ((WebControl)btn).Visible = false;
                                 }
                             }
                             else if (btn.CommandName == "Delete")
                             {
                                 if (wds != null && !wds.AllowDelete)
                                 {
                                     ((WebControl)btn).Visible = false;
                                 }
                             }
                             else if (btn.CommandName == "New")
                             {
                                 if (wds != null && !wds.AllowAdd)
                                 {
                                     ((WebControl)btn).Visible = false;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
		protected virtual DetailsViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState)
		{
			DetailsViewRow row = new DetailsViewRow (rowIndex, rowType, rowState);
			OnItemCreated (EventArgs.Empty);
			return row;
		}
Example #19
0
 protected void InitNavControls(DetailsViewRow row)
 {
     nav.ID = "InPageNavigatorForAddAndQuery";
     nav.AddDefaultControls = false;
     string[] ctrlTexts = { "apply", "abort", "query" };
     if (this.GetServerText)
     {
         //language = CliSysMegLag.GetClientLanguage();
         language = CliUtils.fClientLang;
         String message = SysMsg.GetSystemMessage(language,
                                                  "Srvtools",
                                                  "WebDetailsView",
                                                  "ControlText", true);
         ctrlTexts = message.Split(';');
     }
     if (this.NavControls.Count == 0)
     {
         #region add default controls
         // Add Apply Control
         ControlItem ApplyItem = new ControlItem
             ("Apply", ctrlTexts[0], this.InnerNavigatorShowStyle, "../image/uipics/apply.gif", "../image/uipics/apply2.gif", "../image/uipics/apply3.gif", 26, true);
         this.NavControls.Add(ApplyItem);
         // Add Abort Control
         ControlItem AbortItem = new ControlItem
             ("Abort", ctrlTexts[1], this.InnerNavigatorShowStyle, "../image/uipics/abort.gif", "../image/uipics/abort2.gif", "../image/uipics/abort3.gif", 26, true);
         this.NavControls.Add(AbortItem);
         // Add Query Control
         ControlItem QueryItem = new ControlItem
             ("Query", ctrlTexts[2], this.InnerNavigatorShowStyle, "../image/uipics/query.gif", "../image/uipics/query2.gif", "../image/uipics/query3.gif", 26, true);
         this.NavControls.Add(QueryItem);
         #endregion
     }
     nav.ShowDataStyle = WebNavigator.NavigatorStyle.DetailStyle;
     nav.BindingObject = this.ID;
     nav.LinkLable = this.InnerNavigatorLinkLabel;
     foreach (WebQueryField f in this.QueryFields)
     {
         nav.QueryFields.Add(f);
     }
     foreach (ControlItem item in this.NavControls)
     {
         if (item.ControlName == "Apply")
             item.ControlText = ctrlTexts[0];
         else if (item.ControlName == "Abort")
             item.ControlText = ctrlTexts[1];
         else if (item.ControlName == "Query")
             item.ControlText = ctrlTexts[2];
         nav.NavControls.Add(item);
     }
     foreach (Control ctrl in row.Cells[0].Controls)
     {
         if (ctrl is Table)
         {
             Table t = (Table)ctrl;
             TableCell tc = new TableCell();
             tc.Controls.Add(nav);
             t.Rows[0].Cells.Add(tc);
             if (this.PageCount == 1)
             {
                 t.Rows[0].Cells[0].Controls.Clear();
             }
             break;
         }
     }
 }
Example #20
0
		public void CopyTo (DetailsViewRow[] array, int index)
		{
			rows.CopyTo (array, index);
		}
 public void CopyTo(DetailsViewRow[] array, int index)
 {
 }
Example #22
0
        /// <devdoc>
        /// <para>Creates the control hierarchy that is used to render the DetailsView.
        /// 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;
            DetailsViewMode mode = Mode;

            // if we're in design mode, PageIndex doesn't return -1
            if (DesignMode && mode == DetailsViewMode.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 != DetailsViewMode.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 != DetailsViewMode.Insert) {
                pagedDataSource.DataSource = dataSource;
            }
            
            IEnumerator dataSourceEnumerator = null;
            OrderedDictionary keyTable = KeyTable;

            _rowsArray = new ArrayList();
            _rowsCollection = null;

            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 != DetailsViewMode.Insert) {
                        ICollection collection = dataSource as ICollection;
                        if ((collection == null) && (pagedDataSource.IsPagingEnabled && !pagedDataSource.IsServerPagingEnabled)) {
                            throw new HttpException(SR.GetString(SR.DetailsView_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 != DetailsViewMode.Insert) {
                // if we're in insert mode and we're not autogenerating rows, render the rows in insert mode
                if (itemIndex >= 0 || AutoGenerateRows) {
                    if (EmptyDataText.Length > 0 || _emptyDataTemplate != null) {
                        _rowsArray.Add(CreateRow(0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, null, 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 the current page 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 && !singlePage && mode != DetailsViewMode.Insert) {
                    // top pager
                    _topPagerRow = CreateRow(-1, DataControlRowType.Pager, DataControlRowState.Normal, null, rows, pagedDataSource);
                }

                _headerRow = CreateRow(-1, DataControlRowType.Header, DataControlRowState.Normal, null, rows, null);
                if (_headerTemplate == null && HeaderText.Length == 0) {
                    _headerRow.Visible = false;
                }

                _rowsArray.AddRange(CreateDataRows(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(-1, DataControlRowType.Footer, DataControlRowState.Normal, null, rows, null);
                if (_footerTemplate == null && FooterText.Length == 0) {
                    _footerRow.Visible = false;
                }

                if (allowPaging && PagerSettings.Visible && _pagerSettings.IsPagerOnBottom && !singlePage && mode != DetailsViewMode.Insert) {
                    // bottom pager
                    _bottomPagerRow = CreateRow(-1, DataControlRowType.Pager, DataControlRowState.Normal, null, rows, pagedDataSource);
                }
            }

            _pageCount = itemCount;

            OnItemCreated(EventArgs.Empty);
            
            if (dataBinding) {
                DataBind(false);
            }

            return itemCount;
        }
 protected virtual new void InitializePager(DetailsViewRow row, PagedDataSource pagedDataSource)
 {
 }
Example #24
0
        /// <devdoc>
        /// <para>[To be supplied.]</para>
        /// </devdoc>
        protected virtual void InitializeRow(DetailsViewRow row, DataControlField field) {
            TableCellCollection cells = row.Cells;
            DataControlFieldCell contentCell = new DataControlFieldCell(field);
            ITemplate contentTemplate = null;
            int itemIndex = DataItemIndex;
            DataControlRowState rowState = row.RowState;

            switch (row.RowType) {
                case DataControlRowType.DataRow:
                    if (field.ShowHeader) {
                        DataControlFieldCell headerTextCell = new DataControlFieldCell(field);
                        field.InitializeCell(headerTextCell, DataControlCellType.Header, rowState, itemIndex);
                        cells.Add(headerTextCell);
                    }
                    else {
                        contentCell.ColumnSpan = 2;
                    }
                    field.InitializeCell(contentCell, DataControlCellType.DataCell, rowState, itemIndex);
                    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);
        }
 protected virtual new void InitializeRow(DetailsViewRow row, DataControlField field)
 {
 }
		protected virtual DetailsViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState)
		{
			DetailsViewRow row;
			if (rowType == DataControlRowType.Pager)
				row = new DetailsViewPagerRow (rowIndex, rowType, rowState);
			else
				row = new DetailsViewRow (rowIndex, rowType, rowState);
			return row;
		}
		protected override int CreateChildControls (IEnumerable data, bool dataBinding)
		{
			PagedDataSource dataSource = new PagedDataSource ();
			dataSource.DataSource = CurrentMode != DetailsViewMode.Insert ? data : null;
			dataSource.AllowPaging = AllowPaging;
			dataSource.PageSize = 1;
			dataSource.CurrentPageIndex = PageIndex;

			if (dataBinding && CurrentMode != DetailsViewMode.Insert) {
				DataSourceView view = GetData ();
				if (view != null && view.CanPage) {
					dataSource.AllowServerPaging = true;
					if (SelectArguments.RetrieveTotalRowCount)
						dataSource.VirtualCount = SelectArguments.TotalRowCount;
				}
			}

			bool showPager = AllowPaging && (dataSource.PageCount > 1);

			Controls.Clear ();
			table = CreateTable ();
			Controls.Add (table);
			headerRow = null;
			footerRow = null;
			topPagerRow = null;
			bottomPagerRow = null;
			ArrayList list = new ArrayList ();

			// 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;
				}
			}

			if (PageCount == 0 && CurrentMode != DetailsViewMode.Insert) {
				DetailsViewRow row = CreateEmptyRow ();
				if (row != null) {
					table.Rows.Add (row);
					list.Add (row);
				}
			}
			else {

				// Creates the set of fields to show

				ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding && dataItem != null);
				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

				headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal);
				DataControlFieldCell headerCell = new DataControlFieldCell (null);
				headerCell.ColumnSpan = 2;
				if (headerTemplate != null)
					headerTemplate.InstantiateIn (headerCell);
				else if (!String.IsNullOrEmpty (HeaderText))
					headerCell.Text = HeaderText;
				else
					headerRow.Visible = false;
				headerRow.Cells.Add (headerCell);
				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);
				}

				foreach (DataControlField field in fields) {
					DataControlRowState rstate = GetRowState (list.Count);
					DetailsViewRow row = CreateRow (PageIndex, DataControlRowType.DataRow, rstate);
					InitializeRow (row, field);
					table.Rows.Add (row);
					list.Add (row);
				}

				footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal);
				DataControlFieldCell footerCell = new DataControlFieldCell (null);
				footerCell.ColumnSpan = 2;
				if (footerTemplate != null)
					footerTemplate.InstantiateIn (footerCell);
				else if (!String.IsNullOrEmpty (FooterText))
					footerCell.Text = FooterText;
				else
					footerRow.Visible = false;
				footerRow.Cells.Add (footerCell);
				table.Rows.Add (footerRow);

				if (showPager && PagerSettings.Position == PagerPosition.Bottom ||
						PagerSettings.Position == PagerPosition.TopAndBottom) {
					bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
					InitializePager (bottomPagerRow, dataSource);
					table.Rows.Add (bottomPagerRow);
				}
			}
			
			rows = new DetailsViewRowCollection (list);

			if (dataBinding)
				DataBind (false);
			
			OnItemCreated (EventArgs.Empty);

			return PageCount;
		}
			protected override void InitializePager (DetailsViewRow row, PagedDataSource pagedDataSource)
			{
				base.InitializePager (row,pagedDataSource);
				isInitializePager = true;
			}
 protected virtual new void InitializePager (DetailsViewRow row, PagedDataSource pagedDataSource)
 {
   Contract.Requires (this.PagerSettings != null);
   Contract.Requires (row != null);
   Contract.Requires (row.Cells != null);
 }