DataControlField.InitializeCell Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Agrega texto o controles a la colección de controles de una celda.
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
que DataControlFieldCell contiene el texto o los controles de .DataControlField
- cellType
- DataControlCellType
Uno de los DataControlCellType valores.
- rowState
- DataControlRowState
Uno de los DataControlRowState valores, especificando el estado de la fila que contiene .DataControlFieldCell
- rowIndex
- Int32
Índice de la fila en la que se encuentra .DataControlFieldCell
Ejemplos
En el ejemplo de código siguiente se muestra cómo implementar el InitializeCell método para un control que deriva de la DataControlField clase . La RadioButtonField clase representa un botón de radio enlazado a datos para cada fila de un GridView control. Cuando la fila muestra datos a un usuario y no está en modo de edición, el RadioButton control está deshabilitado. Cuando la fila está en modo de edición, por ejemplo, cuando el usuario elige actualizar una fila en el GridView control, el RadioButton control se representa como habilitado para que se pueda hacer clic en él. En este ejemplo se usan operadores AND bit a bit, ya que el estado de fila puede ser una combinación de uno o varios 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
Comentarios
Los tipos derivados de DataControlField implementan el InitializeCell método para agregar texto y controles a un DataControlFieldCell objeto que pertenece a un control de datos que usa tablas para mostrar una interfaz de usuario (UI). Estos controles de datos crean la fila completa de estructura de tabla por fila cuando se llama a sus métodos respectivos CreateChildControls . El InitializeCell método llama al InitializeRow método de controles de datos como DetailsView y GridView.
Llame a este método cuando escriba un control enlazado a datos personalizado que use DataControlFieldCell objetos para inicializar las celdas de la estructura de la tabla con datos o controles. Implemente este método cuando escriba una clase derivada de DataControlField.