/// <summary> /// 初始化为指定的行状态。 /// </summary> /// <param name="cell"></param> /// <param name="cellType"></param> /// <param name="rowState"></param> /// <param name="rowIndex"></param> public override void InitializeCell(DataControlFieldCellEx cell, DataControlCellType cellType, DataGridViewRowState rowState, int rowIndex) { string headerText = string.Empty; bool flag = false, flag2 = false; if ((cellType == DataControlCellType.Header) && this.SupportsHtmlEncode && this.HtmlEncode) { headerText = this.HeaderText; flag2 = true; } if (flag2 && !string.IsNullOrEmpty(headerText)) { this.supressHeaderTextFieldChange = true; this.HeaderText = HttpUtility.HtmlEncode(headerText); flag = true; } base.InitializeCell(cell, cellType, rowState, rowIndex); if (flag) { this.HeaderText = headerText; this.supressHeaderTextFieldChange = false; } if (cellType == DataControlCellType.DataCell) { if (this.ShowRowSelectingEvent) { IButtonControl control; IPostBackContainer container = base.Control as IPostBackContainer; if (container != null) { control = new DataControlLinkButton(container); } else control = new LinkButton(); control.CommandName = "RowSelectingEvent"; control.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture); ((WebControl)control).DataBinding += new EventHandler(this.OnDataBindField); cell.Controls.Add((WebControl)control); } else this.InitializeDataCell(cell, rowState); } }
/// <summary> /// 将文本或控件添加到单元格的控件集合中。 /// </summary> /// <param name="cell"></param> /// <param name="cellType"></param> /// <param name="rowState"></param> /// <param name="rowIndex"></param> public virtual void InitializeCell(DataControlFieldCellEx cell, DataControlCellType cellType, DataGridViewRowState rowState, int rowIndex) { WebControl control = null; string sortExpression = string.Empty, headerText = string.Empty; ImageButton button = null; switch (cellType) { case DataControlCellType.Header: { control = null; sortExpression = this.SortExpression; bool bSort = this.sortingEnabled && !string.IsNullOrEmpty(sortExpression); string headerImageUrl = this.HeaderImageUrl; headerText = this.HeaderText; if (string.IsNullOrEmpty(headerImageUrl)) { if (bSort) { LinkButton link = null; IPostBackContainer container = this.control as IPostBackContainer; if (container != null) { link = new DataControlLinkButton(container); ((DataControlLinkButton)link).EnableCallback(null); } else link = new LinkButton(); link.Text = headerText; link.CommandName = "Sort"; link.CommandArgument = sortExpression; if (!(link is DataControlLinkButton)) link.CausesValidation = false; control = link; } else { if (string.IsNullOrEmpty(headerText)) headerText = " "; cell.Text = headerText; } goto Label_015C; } if (!bSort && !string.IsNullOrEmpty(headerImageUrl)) { Image image = new Image(); image.ImageUrl = headerImageUrl; control = image; image.AlternateText = headerText; goto Label_015C; } IPostBackContainer contrainer = this.control as IPostBackContainer; if (contrainer == null) { button = new ImageButton(); break; } button = new DataControlImageButton(contrainer); ((DataControlImageButton)button).EnableCallback(null); } break; case DataControlCellType.Footer: { string footerText = this.FooterText; if (string.IsNullOrEmpty(footerText)) footerText = " "; cell.Text = footerText; } return; default: return; } button.ImageUrl = this.HeaderImageUrl; button.CommandName = "Sort"; button.CommandArgument = sortExpression; if (!(button is DataControlImageButton)) button.CausesValidation = false; button.AlternateText = headerText; control = button; Label_015C: if (control != null) cell.Controls.Add(control); }