共用方式為


DataControlField.ExtractValuesFromCell 方法

定義

從目前資料表儲存格中擷取資料控制項欄位的值,並將值加入至指定的 IDictionary 集合。

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)

參數

cell
DataControlFieldCell

DataControlFieldCell,其中包含 DataControlField 的文字或控制項。

rowState
DataControlRowState

其中一個 DataControlRowState 值。

includeReadOnly
Boolean

true 表示唯讀欄位的值包含在 dictionary 集合中,否則為 false

範例

下列程式碼範例示範如何為衍生自 類別的 DataControlField 控制項實 ExtractValuesFromCell 作 方法。 類別 RadioButtonField 會呈現 控制項中 GridView 每個資料列的資料繫結選項按鈕。 ExtractValuesFromCell呼叫 方法時,方法會嘗試判斷儲存格中包含的物件目前值 RadioButton 是否已選取或清除,並將值新增至 IDictionary 集合。 此程式碼範例是針對 類別提供的較大範例的 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

備註

方法 ExtractValuesFromCell 是由衍生自 DataControlField 的類型所實作,以在適用的情況下將目前欄位與值產生關聯。 欄位/值組會儲存在 dictionary 傳遞至 方法的集合中。 方法 ExtractValuesFromCell 是由 ExtractRowValues 和 等 DetailsViewGridView 資料控制項的 方法呼叫。

當您撰寫使用 DataControlFieldCell 物件來組合一組儲存格及其相關聯值的自訂資料繫結控制項時,請呼叫這個方法。 當您撰寫衍生自 DataControlField 的類別,以顯示使用者資料或資料系結資料時,請實作這個方法。 並非所有衍生類型都實作 ExtractValuesFromCell 方法,因為並非所有欄位都會顯示使用者資料。 例如, ButtonField 控制項會顯示按鈕,而且沒有使用者資料。

適用於

另請參閱