DataControlField.ExtractValuesFromCell 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从当前表格单元格中提取数据控件字段的值,并将该值添加到指定的 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)
参数
- dictionary
- IOrderedDictionary
- cell
- DataControlFieldCell
一个 DataControlFieldCell,包含 DataControlField 的文本或控件。
- rowState
- DataControlRowState
DataControlRowState 值之一。
- includeReadOnly
- Boolean
如果要指示只读字段的值包括在 dictionary
集合中,则为 true
;否则为 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
数据控件的方法(如 DetailsView 和 GridView)调用。
编写使用 DataControlFieldCell 对象组合一组单元格及其关联值的自定义数据绑定控件时调用此方法。 编写派生自 DataControlField 显示用户数据或数据绑定数据的类时,实现此方法。 并非所有派生类型都实现该方法 ExtractValuesFromCell ,因为并非所有字段都显示用户数据。 例如,控件 ButtonField 显示一个按钮,没有用户数据。