Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ExtractValuesFromCell Method

DataControlField.ExtractValuesFromCell Method

Note: This method is new in the .NET Framework version 2.0.

Extracts the value of the data control field from the current table cell and adds the value to the specified IDictionary collection.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual void ExtractValuesFromCell (
	IOrderedDictionary dictionary,
	DataControlFieldCell cell,
	DataControlRowState rowState,
	bool includeReadOnly
)
public void ExtractValuesFromCell (
	IOrderedDictionary dictionary, 
	DataControlFieldCell cell, 
	DataControlRowState rowState, 
	boolean includeReadOnly
)
public function ExtractValuesFromCell (
	dictionary : IOrderedDictionary, 
	cell : DataControlFieldCell, 
	rowState : DataControlRowState, 
	includeReadOnly : boolean
)

Parameters

dictionary

An IOrderedDictionary.

cell

A DataControlFieldCell that contains the text or controls of the DataControlField.

rowState

One of the DataControlRowState values.

includeReadOnly

true to indicate that the values of read-only fields are included in the dictionary collection; otherwise, false.

The ExtractValuesFromCell method is implemented by types derived from DataControlField to associate the current field with a value, if applicable. The field/value pair is stored in the dictionary collection that is passed to the method. The ExtractValuesFromCell method is called by the ExtractRowValues method of data controls such as DetailsView and GridView.

Call this method when you are writing a custom data-bound control that uses DataControlFieldCell objects to assemble a set of cells and their associated values. Implement this method when you are writing a class derived from DataControlField that displays user data or data-bound data. Not all derived types implement the ExtractValuesFromCell method, because not all fields display user data. For example, the ButtonField control displays a button and has no user data.

The following code example demonstrates how to implement the ExtractValuesFromCell method for a control that derives from the DataControlField class. The RadioButtonField class renders a data-bound radio button for every row in a GridView control. When the ExtractValuesFromCell method is called, the method attempts to determine whether the current value of the RadioButton object contained in the cell is selected or cleared, and adds the value to the IDictionary collection. This code example is part of a larger example provided for the DataControlField class.

// 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 on GridView 
//and DetailsView. Retrieve
// the current value of the cell from the Checked state of the Radio button.
public void ExtractValuesFromCell(IOrderedDictionary dictionary, 
    DataControlFieldCell cell, DataControlRowState rowState, 
    boolean includeReadOnly) throws InvalidOperationException
{
    // Does the cell contain a RadioButton in its Controls collection?
    if (cell.get_Controls().get_Count() > 0) {
        RadioButton radio = (RadioButton)cell.get_Controls().get_Item(0);

        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 = (System.Boolean)radio.get_Checked();
        }
        // Add the value of the Checked attribute of the
        // RadioButton to the dictionary.
        if (dictionary.Contains(get_DataField())) {
            dictionary.set_Item(get_DataField(), checkedValue);
        }
        else {
            dictionary.Add(get_DataField(), checkedValue);
        }
    }
} //ExtractValuesFromCell

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft