protected override void OnRowCreated(GridViewRowEventArgs e) { base.OnRowCreated(e); if (e.Row.RowType == DataControlRowType.Footer && this.ShowFooter) { #region 如果当前生成的Row是FooterRow int p = this.Columns.Count; DataControlField[] fields = new DataControlField[p]; for (int q = 0; q < p; q++) { fields[q] = this.Columns[q]; } if (this.GridInserting) { bool crRowExist = false; bool dvExist = false; object[,] carValues = null; object[,] defaultValues = null; WebDefault def = new WebDefault(); bool asExist = false; string autoseqvalue = ""; string autoseqfield = ""; Hashtable tableautoseq = new Hashtable(); WebAutoSeq aus = new WebAutoSeq(); if (this.Page.Form != null) { def = (WebDefault)this.ExtendedFindChildControl(this.DataSourceID, FindControlType.DataSourceID, typeof(WebDefault)); // CarryOn // 从ViewStates读出之前Insert的那一笔的Keys和Values,以便做CarryOn List<object> preKeys = (List<object>)this.ViewState["PreAddKeys"]; List<object> preValues = (List<object>)this.ViewState["PreAddValues"]; if (def != null) { if (def.CarryOnActive && preKeys != null && preValues != null && preKeys.Count != 0 && preValues.Count != 0) { int i = preKeys.Count; carValues = new object[i, 2]; for (int j = 0; j < i; j++) { carValues[j, 0] = preKeys[j]; carValues[j, 1] = preValues[j]; } crRowExist = true; } // DefaultValue if (def.DefaultActive) { defaultValues = def.GetDefaultValues(); dvExist = true; } } //autoseq add by ccm // ControlCollection collection = (this.Page.Master == null) ? this.Page.Form.Controls : this.Parent.Controls; foreach (Control ctrl in collection) { if (ctrl is WebAutoSeq && ((WebAutoSeq)ctrl).DataSourceID == this.DataSourceID && ((WebAutoSeq)ctrl).Active) { aus = (WebAutoSeq)ctrl; autoseqvalue = aus.GetValue(); autoseqfield = aus.FieldName; if (!tableautoseq.ContainsKey(autoseqfield)) { tableautoseq.Add(autoseqfield, autoseqvalue); } asExist = true; } } //end add } #region Default和CarryOn赋值, 如果是detail,则带key值 int x = this.Columns.Count; for (int y = 0; y < x; y++) { string FieldName = ""; // 如果當前Cell所在Column是CommandField或者Column的SortExpression和HeadText有一個為空時,跳岀本次循環 if (this.Columns[y] is CommandField || ((this.Columns[y].SortExpression == null || this.Columns[y].SortExpression == "") && (this.Columns[y].HeaderText == null || this.Columns[y].HeaderText == ""))) { continue; } // 如果当前Cell所在Column是BoundField,那么FieldName为DataField属性 if (this.Columns[y] is BoundField) FieldName = ((BoundField)this.Columns[y]).DataField; // 否则FieldName为SortExpression属性 else FieldName = this.Columns[y].SortExpression; object value = null; // DefaultValue if (dvExist) { int m = defaultValues.Length / 2; for (int n = 0; n < m; n++) { if (FieldName == defaultValues[n, 0].ToString() && defaultValues[n, 1] != null && defaultValues[n, 1].ToString() != "") { value = defaultValues[n, 1]; } } } // CarrayOn if (crRowExist) { int m = carValues.Length / 2; for (int n = 0; n < m; n++) { if (def.Fields[FieldName] != null && ((DefaultFieldItem)def.Fields[FieldName]).CarryOn && FieldName == carValues[n, 0].ToString()) { value = carValues[n, 1]; } } } // AutoSeq if (asExist) { if (tableautoseq.ContainsKey(FieldName)) { value = tableautoseq[FieldName]; } } // 带key值给detail if (this.Page != null && this.Page.Form != null) { WebDataSource datasource = this.GetObjByID(this.DataSourceID) as WebDataSource; if (datasource != null && !string.IsNullOrEmpty(datasource.MasterDataSource) && datasource.RelationValues.Contains(FieldName)) { value = datasource.RelationValues[FieldName]; } } CellControls.Clear(); GetAllCellControls(e.Row.Cells[y]); foreach (Control ctrl in CellControls) { if (value != null) { if (ctrl is TextBox) { ((TextBox)ctrl).Text = value.ToString(); } if (ctrl is HiddenField) { ((HiddenField)ctrl).Value = value.ToString(); } if (ctrl is Label) { ((Label)ctrl).Text = value.ToString(); } if (ctrl is DropDownList) { ((DropDownList)ctrl).SelectedValue = value.ToString(); } if (ctrl is CheckBox) { ((CheckBox)ctrl).Checked = Convert.ToBoolean(value); if (ctrl is WebCheckBox) { (ctrl as WebCheckBox).RefreshBindingValue(); } } if (ctrl is WebRefValBase) { ((WebRefValBase)ctrl).BindingValue = value.ToString(); } if (ctrl is IDateTimePicker) { if (((IDateTimePicker)ctrl).DateTimeType == dateTimeType.DateTime) { ((IDateTimePicker)ctrl).Text = value.ToString(); } else if (((IDateTimePicker)ctrl).DateTimeType == dateTimeType.VarChar) { try { DateTime dt = Convert.ToDateTime(value); ((IDateTimePicker)ctrl).DateString = dt.ToString("yyyyMMdd"); } catch { ((IDateTimePicker)ctrl).DateString = value.ToString(); } } } if (ctrl is Label) { ((Label)ctrl).Text = value.ToString(); } } } } #endregion } else if (!this.GridInserting && this.TotalActive) { int i = fields.Length; for (int j = 0; j < i; j++) { string fieldName = ""; if (fields[j] is BoundField) { fieldName = ((BoundField)fields[j]).DataField; } else if (fields[j] is ExpressionField) { fieldName = ((ExpressionField)fields[j]).Expression; } else { fieldName = fields[j].SortExpression; } e.Row.Cells[j].Controls.Clear(); if (fieldName != "") { foreach (GridViewTotalItem item in this.TotalColumns) { if (item.FieldName == fieldName && item.ShowTotal) { Label lbl = new Label(); if (this.Site == null) lbl.Text = GetTotalValue(fieldName, item.TotalMode, item.Format); else lbl.Text = "Total"; e.Row.Cells[j].Controls.Add(lbl); } } } else { if (j == 0) { Label lbl = new Label(); lbl.Text = this.TotalCaption; e.Row.Cells[j].Controls.Add(lbl); } } } } #endregion } }