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

DataControlFieldのテキストまたはコントロールを含むDataControlFieldCell

cellType
DataControlCellType

DataControlCellType値の 1 つ。

rowState
DataControlRowState

DataControlFieldCellを含む行の状態を指定する、DataControlRowState値の 1 つ。

rowIndex
Int32

DataControlFieldCellが含まれる行のインデックス。

次のコード例では、DataControlField クラスから派生するコントロールのInitializeCell メソッドを実装する方法を示します。 RadioButtonField クラスは、GridView コントロール内のすべての行のデータ バインドラジオ ボタンをレンダリングします。 行がユーザーにデータを表示していて、編集モードでない場合、 RadioButton コントロールは無効になります。 ユーザーが GridView コントロールの行を更新することを選択した場合など、行が編集モードの場合、 RadioButton コントロールはクリックできるように有効としてレンダリングされます。 この例では、行の状態が 1 つ以上の DataControlRowState 値の組み合わせである可能性があるため、ビットごとの AND 演算子を使用します。

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

注釈

DataControlFieldから派生した型は、InitializeCell メソッドを実装して、テーブルを使用してユーザー インターフェイス (UI) を表示するデータ コントロールに属するDataControlFieldCell オブジェクトにテキストとコントロールを追加します。 これらのデータ コントロールは、それぞれの CreateChildControls メソッドが呼び出されたときに、テーブル構造全体を行ごとに作成します。 InitializeCell メソッドは、DetailsViewGridViewなどのデータ コントロールのInitializeRow メソッドによって呼び出されます。

DataControlFieldCell オブジェクトを使用してデータまたはコントロールを使用してテーブル構造のセルを初期化するカスタム データ バインド コントロールを作成するときに、このメソッドを呼び出します。 DataControlFieldから派生したクラスを記述するときに、このメソッドを実装します。

適用対象

こちらもご覧ください