/// <summary> /// 复制。 /// </summary> /// <param name="newField"></param> protected override void CopyProperties(DataControlFieldEx newField) { ((TemplateFieldEx)newField).ConvertEmptyStringToNull = this.ConvertEmptyStringToNull; ((TemplateFieldEx)newField).AlternatingItemTemplate = this.AlternatingItemTemplate; ((TemplateFieldEx)newField).ItemTemplate = this.ItemTemplate; ((TemplateFieldEx)newField).FooterTemplate = this.FooterTemplate; ((TemplateFieldEx)newField).HeaderTemplate =this.HeaderTemplate; base.CopyProperties(newField); }
/// <summary> /// 构造函数。 /// </summary> /// <param name="containingField"></param> public DataControlFieldCellEx(DataControlFieldEx containingField) { this.containingField = containingField; }
/// <summary> /// 将当前 CheckBoxFieldEx<seealso cref="CheckBoxFieldEx"/> 对象的属性复制到指定的 DataControlField<see cref="DataControlField"/> 对象。 /// </summary> /// <param name="newField">当前 CheckBoxFieldEx<seealso cref="CheckBoxFieldEx"/> 的属性将复制到的 DataControlField<see cref="DataControlField"/>。</param> protected override void CopyProperties(DataControlFieldEx newField) { ((CheckBoxFieldEx)newField).DataField = this.DataField; base.CopyProperties(newField); }
/// <summary> /// 将指定的 <see cref="DataControlFieldEx"/> 对象追加到集合的结尾。 /// </summary> /// <param name="field"></param> public void Add(DataControlFieldEx field) { ((IList)this).Add(field); }
/// <summary> /// 构造函数。 /// </summary> /// <param name="containingField"></param> public DataControlFieldHeaderCellEx(DataControlFieldEx containingField) : base(containingField) { }
/// <summary> /// 将指定的 <see cref="DataControlFieldEx"/> 对象插入<see cref="DataControlFieldExCollection"/> 集合中指定的索引位置。 /// </summary> /// <param name="index"></param> /// <param name="field"></param> public void Insert(int index, DataControlFieldEx field) { ((IList)this).Insert(index, field); }
/// <summary> /// 从 <see cref="DataControlFieldExCollection"/> 集合中移除指定的<see cref="DataControlFieldEx"/> 对象。 /// </summary> /// <param name="field"></param> public void Remove(DataControlFieldEx field) { ((IList)this).Remove(field); }
/// <summary> /// 复制。 /// </summary> /// <param name="array"></param> /// <param name="index"></param> public void CopyTo(DataControlFieldEx[] array, int index) { this.CopyTo(array, index); }
/// <summary> /// 确定集合中特定 <see cref="DataControlFieldEx"/> 对象的索引。 /// </summary> /// <param name="field"></param> /// <returns></returns> public int IndexOf(DataControlFieldEx field) { return ((IList)this).IndexOf(field); }
/// <summary> /// /// </summary> /// <param name="newField"></param> protected override void CopyProperties(DataControlFieldEx newField) { ((MultiQueryStringFieldEx)newField).DataField = this.DataField; base.CopyProperties(newField); ((MultiQueryStringFieldEx)newField).NavigateUrl = this.NavigateUrl; ((MultiQueryStringFieldEx)newField).DataNavigateUrlFormatString = this.DataNavigateUrlFormatString; ((MultiQueryStringFieldEx)newField).DataNavigateUrlField = this.DataNavigateUrlField; ((MultiQueryStringFieldEx)newField).PopupWin = this.PopupWin; ((MultiQueryStringFieldEx)newField).WinType = this.WinType; ((MultiQueryStringFieldEx)newField).WinHeight = this.WinHeight; ((MultiQueryStringFieldEx)newField).WinWidth = this.WinWidth; ((MultiQueryStringFieldEx)newField).Target = this.Target; }
/// <summary> /// 集合中是否包含对象。 /// </summary> /// <param name="field"></param> /// <returns></returns> public bool Contains(DataControlFieldEx field) { return ((IList)this).Contains(field); }
/// <summary> /// 初始化行。 /// </summary> /// <param name="row"></param> /// <param name="fields"></param> protected virtual void InitializeRow(DataGridViewRow row, DataControlFieldEx[] fields) { DataGridViewRowType rowType = row.RowType; DataGridViewRowState rowState = row.RowState; int rowIndex = row.RowIndex; TableCellCollection cells = row.Cells; string rowHeaderColumn = this.RowHeaderColumn; bool useAccessibleHeader = false; if (rowType == DataGridViewRowType.Header) useAccessibleHeader = this.UseAccessibleHeader; for (int i = 0; i < fields.Length; i++) { DataControlFieldCellEx cell = null; DataControlCellType header = DataControlCellType.DataCell; if ((rowType == DataGridViewRowType.Header) && useAccessibleHeader) { cell = new DataControlFieldHeaderCellEx(fields[i]); ((DataControlFieldHeaderCellEx)cell).Scope = TableHeaderScope.Column; ((DataControlFieldHeaderCellEx)cell).AbbreviatedText = fields[i].AccessibleHeaderText; } else { BoundFieldEx field = fields[i] as BoundFieldEx; if (!string.IsNullOrEmpty(rowHeaderColumn) && (field != null) && (field.DataField == rowHeaderColumn)) { cell = new DataControlFieldHeaderCellEx(fields[i]); ((DataControlFieldHeaderCellEx)cell).Scope = TableHeaderScope.Row; } else cell = new DataControlFieldCellEx(fields[i]); } switch (rowType) { case DataGridViewRowType.Header: header = DataControlCellType.Header; break; case DataGridViewRowType.Footer: header = DataControlCellType.Footer; break; default: header = DataControlCellType.DataCell; break; } fields[i].InitializeCell(cell,header, rowState, rowIndex); cells.Add(cell); } }
/// <summary> /// 基础结构。已重载。 创建用于呈现控件层次结构。 /// </summary> /// <param name="dataSource"></param> /// <param name="dataBinding"></param> /// <returns></returns> protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding) { PagedDataSourceEx pagedDataSource = null; #region 获取数据源 if (dataBinding) { bool allowPaging = this.AllowPaging; DataSourceViewEx data = this.GetData(); DataSourceSelectArgumentsEx selectArguments = this.SelectArguments; if (data == null) throw new HttpException("DataBoundControlEx_NullView"); if ((allowPaging && !data.CanPage) && ((dataSource != null) && !(dataSource is ICollection))) { selectArguments.StartRowIndex = this.PageSize * this.PageIndex; selectArguments.MaximumRows = this.PageSize; data.Select(selectArguments, new DataSourceViewSelectCallback(this.SelectCallback)); } if (allowPaging && data.CanPage) { if (data.CanRetrieveTotalRowCount) pagedDataSource = this.CreateServerPagedDataSource(selectArguments.TotalRowCount); else { ICollection collection = dataSource as ICollection; if (collection == null) throw new HttpException("DataBoundControlEx_NeedICollectionOrTotalRowCount"); pagedDataSource = this.CreateServerPagedDataSource(this.PageIndex * this.PageSize + collection.Count); } } else pagedDataSource = this.CreatePagedDataSource(); } else pagedDataSource = this.CreatePagedDataSource(); #endregion ICollection dataCollection = dataSource as ICollection; if (!dataBinding && dataSource != null && dataCollection == null) throw new HttpException("DataControls_DataSourceMustBeCollectionWhenNotDataBinding"); pagedDataSource.DataSource = dataSource; if (pagedDataSource.DataSourceCount == 0) this.PageCount = 0; else this.PageCount = pagedDataSource.PageCount; if (pagedDataSource.IsPagingEnabled) { int pageCount = pagedDataSource.PageCount; if (pagedDataSource.CurrentPageIndex >= pageCount) pagedDataSource.CurrentPageIndex = this.PageIndex = (pageCount - 1) > 0 ? pageCount - 1 : 0; } #region 获取字段 ICollection dataColumns = this.CreateColumns(dataBinding ? pagedDataSource : null, dataBinding); int colCount = (dataColumns != null) ? dataColumns.Count : 0; DataControlFieldEx[] colsArray = new DataControlFieldEx[colCount]; if (colCount > 0) { dataColumns.CopyTo(colsArray, 0); for (int i = 0; i < colsArray.Length; i++) { colsArray[i].Initialize(this.AllowSorting, this); if (this.DetermineRenderClientScript()) colsArray[i].ValidateSupportsCallback(); } } #endregion #region 绘制数据。 int rowIndex = 0, dataSourceIndex = pagedDataSource.FirstIndexInPage; bool isPagingEnabled = pagedDataSource.IsPagingEnabled; int capacity = isPagingEnabled ? pagedDataSource.PageSize : pagedDataSource.DataSourceCount; this.rowsArray = new ArrayList(capacity); this.rowsCollection = null; Table child = this.CreateChildTable(); this.Controls.Add(child); TableRowCollection rows = child.Rows; if (colCount > 0) { this.headerRow = this.CreateRow(-1, -1, DataGridViewRowType.Header, DataGridViewRowState.Normal, dataBinding, null, colsArray, rows, null); if (!this.ShowHeader) this.headerRow.Visible = false; if (dataSource != null) { IEnumerator enumerator = pagedDataSource.GetEnumerator(); DataGridViewRow row = null; while (enumerator.MoveNext()) { object container = enumerator.Current; DataGridViewRowState normal = DataGridViewRowState.Normal; if ((rowIndex % 2) != 0) normal |= DataGridViewRowState.AlterNate; row = this.CreateRow(rowIndex, dataSourceIndex, DataGridViewRowType.DataRow, normal, dataBinding, container, colsArray, rows, null); this.rowsArray.Add(row); dataSourceIndex++; rowIndex++; } if (dataCollection.Count > 0) { this.footerRow = this.CreateRow(-1, -1, DataGridViewRowType.Footer, DataGridViewRowState.Normal, dataBinding, null, colsArray, rows, pagedDataSource); if (!this.ShowFooter) this.footerRow.Visible = false; } } } #endregion return rowIndex; }
DataGridViewRow CreateRow(int rowIndex, int dataSourceIndex, DataGridViewRowType rowType, DataGridViewRowState rowState, bool dataBind, object dataItem, DataControlFieldEx[] fields, TableRowCollection rows, PagedDataSourceEx pagedDataSource) { DataGridViewRow row = this.CreateRow(rowIndex, dataSourceIndex, rowType, rowState); DataGridViewRowEventArgs e = new DataGridViewRowEventArgs(row); if (rowType != DataGridViewRowType.Footer) this.InitializeRow(row, fields); else this.InitializePager(row, fields.Length, pagedDataSource); if (dataBind) row.DataItem = dataItem; this.OnRowCreated(e); rows.Add(row); if (dataBind) { row.DataBind(); this.OnRowDataBound(e); row.DataItem = null; } return row; }
/// <summary> /// 复制属性。 /// </summary> /// <param name="newField"></param> protected override void CopyProperties(DataControlFieldEx newField) { ((BoundFieldEx)newField).DataField = this.DataField; ((BoundFieldEx)newField).ToolTipField = this.ToolTipField; ((BoundFieldEx)newField).DataFormatString = this.DataFormatString; ((BoundFieldEx)newField).HtmlEncode = this.HtmlEncode; ((BoundFieldEx)newField).HtmlEncodeFormatString = this.HtmlEncodeFormatString; base.CopyProperties(newField); }
/// <summary> /// 将当前 <see cref="DataControlFieldEx"/> 派生对象的属性复制到指定的 <see cref="DataControlFieldEx"/> 对象。 /// </summary> /// <param name="newField"></param> protected virtual void CopyProperties(DataControlFieldEx newField) { newField.AccessibleHeaderText = this.AccessibleHeaderText; newField.ControlStyle.CopyFrom(this.ControlStyle); newField.FooterStyle.CopyFrom(this.FooterStyle); newField.HeaderStyle.CopyFrom(this.HeaderStyle); newField.ItemStyle.CopyFrom(this.ItemStyle); newField.FooterText = this.FooterText; newField.HeaderImageUrl = this.HeaderImageUrl; newField.HeaderText = this.HeaderText; newField.ShowHeader = this.ShowHeader; newField.SortExpression = this.SortExpression; newField.Visible = this.Visible; }