DataControlField.InitializeCell Yöntem

Tanım

Hücrenin denetim koleksiyonuna metin veya denetimler ekler.

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)

Parametreler

cell
DataControlFieldCell

DataControlFieldCell metnini veya denetimlerini içeren bir DataControlField.

cellType
DataControlCellType

Değerlerden DataControlCellType biri.

rowState
DataControlRowState

DataControlRowState değerini içeren DataControlFieldCellsatırın durumunu belirten değerlerden biri.

rowIndex
Int32

içinde bulunduğu satırın DataControlFieldCell dizini.

Örnekler

Aşağıdaki kod örneği, sınıfından InitializeCell türetilen DataControlField bir denetim için yönteminin nasıl uygulandığını gösterir. sınıfı, RadioButtonField denetimdeki her satır için veriye bağlı bir GridView radyo düğmesi işler. Satır bir kullanıcıya veri görüntülüyorsa ve düzenleme modunda değilse denetim RadioButton devre dışı bırakılır. Satır düzenleme modundayken, örneğin kullanıcı denetimdeki bir satırı güncelleştirmeyi seçtiğinde GridView , RadioButton denetim tıklanması için etkin olarak işlenir. Bu örnekte bit düzeyinde AND işleçleri kullanılır çünkü satır durumu bir veya daha fazla DataControlRowState değerin birleşimi olabilir.

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

Açıklamalar

türünden DataControlField türetilen türler, kullanıcı arabirimini InitializeCell (UI) görüntülemek için tabloları kullanan bir DataControlFieldCell veri denetimine ait bir nesneye metin ve denetim eklemek için yöntemini uygular. Bu veri denetimleri, ilgili CreateChildControls yöntemleri çağrıldığında satır satır tablo yapısının tamamını oluşturur. InitializeCell yöntemi, ve GridViewgibi DetailsView veri denetimlerinin yöntemi tarafından InitializeRow çağrılır.

Tablo yapısının hücrelerini veri veya denetimlerle başlatmak için nesneleri kullanan DataControlFieldCell özel bir veriye bağlı denetim yazarken bu yöntemi çağırın. öğesinden DataControlFieldtüretilmiş bir sınıf yazarken bu yöntemi uygulayın.

Şunlara uygulanır

Ayrıca bkz.