DataControlField.ExtractValuesFromCell Método

Definición

Extrae el valor del campo de control de datos de la celda de la tabla actual y agrega su valor a la colección IDictionary especificada.

public:
 virtual void ExtractValuesFromCell(System::Collections::Specialized::IOrderedDictionary ^ dictionary, System::Web::UI::WebControls::DataControlFieldCell ^ cell, System::Web::UI::WebControls::DataControlRowState rowState, bool includeReadOnly);
public virtual void ExtractValuesFromCell (System.Collections.Specialized.IOrderedDictionary dictionary, System.Web.UI.WebControls.DataControlFieldCell cell, System.Web.UI.WebControls.DataControlRowState rowState, bool includeReadOnly);
abstract member ExtractValuesFromCell : System.Collections.Specialized.IOrderedDictionary * System.Web.UI.WebControls.DataControlFieldCell * System.Web.UI.WebControls.DataControlRowState * bool -> unit
override this.ExtractValuesFromCell : System.Collections.Specialized.IOrderedDictionary * System.Web.UI.WebControls.DataControlFieldCell * System.Web.UI.WebControls.DataControlRowState * bool -> unit
Public Overridable Sub ExtractValuesFromCell (dictionary As IOrderedDictionary, cell As DataControlFieldCell, rowState As DataControlRowState, includeReadOnly As Boolean)

Parámetros

dictionary
IOrderedDictionary

Una clase IOrderedDictionary.

cell
DataControlFieldCell

DataControlFieldCell que contiene el texto o los controles del objeto DataControlField.

rowState
DataControlRowState

Uno de los valores de DataControlRowState.

includeReadOnly
Boolean

Es true para indicar que los valores de los campos de sólo lectura están incluidos en la colección dictionary; de lo contrario, es false.

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el ExtractValuesFromCell 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 se llama al ExtractValuesFromCell método , el método intenta determinar si el valor actual del RadioButton objeto contenido en la celda está seleccionado o desactivado y agrega el valor a la IDictionary colección. Este ejemplo de código es parte de un ejemplo mayor proporcionado para la clase DataControlField.

// This method is called by the ExtractRowValues methods of 
// GridView and DetailsView. Retrieve the current value of the 
// cell from the Checked state of the Radio button.
public override void ExtractValuesFromCell(IOrderedDictionary dictionary,
                                           DataControlFieldCell cell,
                                           DataControlRowState rowState,
                                           bool includeReadOnly)
{

  // Determine whether the cell contains a RadioButton 
  // in its Controls collection.
  if (cell.Controls.Count > 0) {
    RadioButton radio = cell.Controls[0] as RadioButton;

    object checkedValue = null;
    if (null == radio) {
      // A RadioButton is expected, but a null is encountered.
      // Add error handling.
      throw new InvalidOperationException
          ("RadioButtonField could not extract control.");
    }
    else {
        checkedValue = radio.Checked;
    }

    // Add the value of the Checked attribute of the
    // RadioButton to the dictionary.
    if (dictionary.Contains(DataField))
      dictionary[DataField] = checkedValue;
    else
      dictionary.Add(DataField, checkedValue);
  }
}
' This method is called by the ExtractRowValues methods of
' GridView and DetailsView. Retrieve the current value of the 
' cell from the Checked state of the Radio button.
Public Overrides Sub ExtractValuesFromCell( _
    ByVal dictionary As IOrderedDictionary, _
    ByVal cell As DataControlFieldCell, _
    ByVal rowState As DataControlRowState, _
    ByVal includeReadOnly As Boolean)
    ' Determine whether the cell contain a RadioButton 
    ' in its Controls collection.
    If cell.Controls.Count > 0 Then
        Dim radio As RadioButton = CType(cell.Controls(0), RadioButton)

        Dim checkedValue As Object = Nothing
        If radio Is Nothing Then
            ' A RadioButton is expected, but a null is encountered.
            ' Add error handling.
            Throw New InvalidOperationException( _
                "RadioButtonField could not extract control.")
        Else
            checkedValue = radio.Checked
        End If


        ' Add the value of the Checked attribute of the
        ' RadioButton to the dictionary.
        If dictionary.Contains(DataField) Then
            dictionary(DataField) = checkedValue
        Else
            dictionary.Add(DataField, checkedValue)
        End If
    End If
End Sub

Comentarios

El ExtractValuesFromCell método se implementa mediante tipos derivados de DataControlField para asociar el campo actual a un valor, si procede. El par campo-valor se almacena en la dictionary colección que se pasa al método . El ExtractValuesFromCell método de controles de datos como DetailsView y GridViewllama al ExtractRowValues método .

Llame a este método cuando escriba un control enlazado a datos personalizado que use DataControlFieldCell objetos para ensamblar un conjunto de celdas y sus valores asociados. Implemente este método cuando escriba una clase derivada de DataControlField que muestre datos de usuario o datos enlazados a datos. No todos los tipos derivados implementan el ExtractValuesFromCell método , ya que no todos los campos muestran datos de usuario. Por ejemplo, el ButtonField control muestra un botón y no tiene datos de usuario.

Se aplica a

Consulte también