DataControlField.InitializeCell 方法

定义

将文本或控件添加到单元格的控件集合。

public:
 virtual void InitializeCell(System::Web::UI::WebControls::DataControlFieldCell ^ cell, System::Web::UI::WebControls::DataControlCellType cellType, System::Web::UI::WebControls::DataControlRowState rowState, int rowIndex);
public virtual void InitializeCell(System.Web.UI.WebControls.DataControlFieldCell cell, System.Web.UI.WebControls.DataControlCellType cellType, System.Web.UI.WebControls.DataControlRowState rowState, int rowIndex);
abstract member InitializeCell : System.Web.UI.WebControls.DataControlFieldCell * System.Web.UI.WebControls.DataControlCellType * System.Web.UI.WebControls.DataControlRowState * int -> unit
override this.InitializeCell : System.Web.UI.WebControls.DataControlFieldCell * System.Web.UI.WebControls.DataControlCellType * System.Web.UI.WebControls.DataControlRowState * int -> unit
Public Overridable Sub InitializeCell (cell As DataControlFieldCell, cellType As DataControlCellType, rowState As DataControlRowState, rowIndex As Integer)

参数

cell
DataControlFieldCell

一个包含 .. 的文本或控件的 DataControlFieldCellDataControlField

cellType
DataControlCellType

其中一个 DataControlCellType 值。

rowState
DataControlRowState

值之一,指定包含 <a0/a0> 的行的状态。

rowIndex
Int32

包含的行 DataControlFieldCell 的索引。

示例

下面的代码示例演示如何实现 InitializeCell 派生自类的 DataControlField 控件的方法。 该 RadioButtonField 类为控件中的每个 GridView 行呈现数据绑定单选按钮。 当行向用户显示数据且未处于编辑模式时,控件 RadioButton 将被禁用。 当行处于编辑模式时,例如,当用户选择更新控件中的 GridView 行时,该 RadioButton 控件将呈现为启用状态,以便单击该控件。 此示例使用按位 AND 运算符,因为行状态可能是一个或多个 DataControlRowState 值的组合。

// This method adds a RadioButton control and any other 
// content to the cell's Controls collection.
protected override void InitializeDataCell
    (DataControlFieldCell cell, DataControlRowState rowState) {

  RadioButton radio = new RadioButton();

  // If the RadioButton is bound to a DataField, add
  // the OnDataBindingField method event handler to the
  // DataBinding event.
  if (DataField.Length != 0) {
    radio.DataBinding += new EventHandler(this.OnDataBindField);
  }

  radio.Text = this.Text;

  // Because the RadioButtonField is a BoundField, it only
  // displays data. Therefore, unless the row is in edit mode,
  // the RadioButton is displayed as disabled.
  radio.Enabled = false;
  // If the row is in edit mode, enable the button.
  if ((rowState & DataControlRowState.Edit) != 0 ||
      (rowState & DataControlRowState.Insert) != 0) {
    radio.Enabled = true;
  }

  cell.Controls.Add(radio);
}
' This method adds a RadioButton control and any other 
' content to the cell's Controls collection.
Protected Overrides Sub InitializeDataCell( _
    ByVal cell As DataControlFieldCell, _
    ByVal rowState As DataControlRowState)

    Dim radio As New RadioButton()

    ' If the RadioButton is bound to a DataField, add
    ' the OnDataBindingField method event handler to the
    ' DataBinding event.
    If DataField.Length <> 0 Then
        AddHandler radio.DataBinding, AddressOf Me.OnDataBindField
    End If

    radio.Text = Me.Text

    ' Because the RadioButtonField is a BoundField, it only 
    ' displays data. Therefore, unless the row is in edit mode, 
    ' the RadioButton is displayed as disabled.
    radio.Enabled = False
    ' If the row is in edit mode, enable the button.
    If (rowState And DataControlRowState.Edit) <> 0 _
        OrElse (rowState And DataControlRowState.Insert) <> 0 Then
        radio.Enabled = True
    End If

    cell.Controls.Add(radio)
End Sub

注解

派生自DataControlFieldInitializeCell实现方法的类型,用于向属于使用表显示用户界面(UI)的数据控件的对象添加文本和控件DataControlFieldCell。 调用各自的 CreateChildControls 方法时,这些数据控件按行创建完整的表结构行。 该方法 InitializeCellInitializeRow 数据控件的方法(如 DetailsViewGridView)调用。

编写使用对象通过数据或控件初始化表结构的单元格的自定义数据绑定控件 DataControlFieldCell 时调用此方法。 编写派生自 DataControlField的类时实现此方法。

适用于

另请参阅