DataControlField.InitializeCell Metoda

Definicja

Dodaje tekst lub kontrolki do kolekcji kontrolek komórki.

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)

Parametry

cell
DataControlFieldCell

Obiekt DataControlFieldCell zawierający tekst lub kontrolki obiektu DataControlField.

cellType
DataControlCellType

DataControlCellType Jedna z wartości.

rowState
DataControlRowState

DataControlRowState Jedna z wartości określających stan wiersza zawierającego element DataControlFieldCell.

rowIndex
Int32

Indeks wiersza, w ramach którego DataControlFieldCell znajduje się element .

Przykłady

W poniższym przykładzie kodu pokazano, jak zaimplementować metodę InitializeCell dla kontrolki pochodzącej DataControlField z klasy . Klasa RadioButtonField renderuje przycisk radiowy powiązany z danymi dla każdego wiersza w kontrolce GridView . Gdy wiersz wyświetla dane użytkownikowi i nie jest w trybie edycji, kontrolka jest wyłączona RadioButton . Gdy wiersz jest w trybie edycji, na przykład gdy użytkownik zdecyduje się zaktualizować wiersz w kontrolce GridView , kontrolka RadioButton jest renderowana jako włączona, aby można ją było kliknąć. W tym przykładzie użyto operatorów BITOWE AND, ponieważ stan wiersza może być kombinacją co najmniej jednej DataControlRowState wartości.

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

Uwagi

Typy pochodzące z DataControlField implementacji InitializeCell metody w celu dodania tekstu i kontrolek do obiektu należącego do DataControlFieldCell kontrolki danych, która używa tabel do wyświetlania interfejsu użytkownika. Te kontrolki danych tworzą kompletny wiersz struktury tabeli według wiersza, gdy są wywoływane odpowiednie CreateChildControls metody. Metoda jest wywoływana InitializeCell przez metodę InitializeRow kontrolek danych, takich jak DetailsView i GridView.

Wywołaj tę metodę podczas pisania niestandardowej kontrolki powiązanej z danymi, która używa DataControlFieldCell obiektów do inicjowania komórek struktury tabeli przy użyciu danych lub kontrolek. Zaimplementuj tę metodę podczas pisania klasy pochodnej z DataControlFieldklasy .

Dotyczy

Zobacz też