DataControlField.InitializeCell Método

Definição

Adiciona texto ou controlos à coleção de controlos de uma célula.

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)

Parâmetros

cell
DataControlFieldCell

A DataControlFieldCell que contém o texto ou controlos do DataControlField.

cellType
DataControlCellType

Um dos DataControlCellType valores.

rowState
DataControlRowState

Um dos DataControlRowState valores, especificando o estado da linha que contém o DataControlFieldCell.

rowIndex
Int32

O índice da linha em que o DataControlFieldCell está contido.

Exemplos

O exemplo de código seguinte demonstra como implementar o InitializeCell método para um controlo que deriva da DataControlField classe. A RadioButtonField classe renderiza um botão de acesso a dados para cada linha de um GridView controlo. Quando a linha está a mostrar dados a um utilizador e não está em modo de edição, o RadioButton controlo é desativado. Quando a linha está em modo de edição, por exemplo, quando o utilizador escolhe atualizar uma linha no GridView controlo, o RadioButton controlo é renderizado como ativado para que possa ser clicado. Este exemplo usa operadores AND bit a bit, porque o estado da linha pode ser uma combinação de um ou mais DataControlRowState valores.

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

Observações

Tipos derivados de DataControlField implementam o InitializeCell método para adicionar texto e controlos a um DataControlFieldCell objeto que pertence a um controlo de dados que utiliza tabelas para mostrar uma interface de utilizador (UI). Estes controlos de dados criam a estrutura completa da tabela linha a linha quando os respetivos CreateChildControls métodos são chamados. O InitializeCell método é chamado pelo InitializeRow método dos controlos de dados como DetailsView e GridView.

Chame este método quando estiver a escrever um controlo personalizado data-bound que usa DataControlFieldCell objetos para inicializar as células da estrutura da tabela com dados ou controlos. Implemente este método quando estiver a escrever uma classe derivada de DataControlField.

Aplica-se a

Ver também