DataControlFieldCollection 類別

定義

表示由 GridViewDetailsView 等資料繫結控制項所使用的 DataControlField 物件集合。Represents a collection of DataControlField objects that are used by data-bound controls such as GridView and DetailsView.

public ref class DataControlFieldCollection sealed : System::Web::UI::StateManagedCollection
public sealed class DataControlFieldCollection : System.Web.UI.StateManagedCollection
type DataControlFieldCollection = class
    inherit StateManagedCollection
Public NotInheritable Class DataControlFieldCollection
Inherits StateManagedCollection
繼承
DataControlFieldCollection

備註

DataControlFieldCollection類別表示 DataControlField 資料繫結控制項所使用的物件集合,用以指定其子控制項的呈現方式。The DataControlFieldCollection class represents a collection of DataControlField objects used by data-bound controls to specify how their child controls are presented. DataControlFieldCollection類別衍生自 StateManagedCollection ,這是特別用來儲存物件的抽象基底集合類別 IStateManagerThe DataControlFieldCollection class derives from StateManagedCollection, an abstract base collection class used specifically to store IStateManager objects.

StateManagedCollection物件會影響物件的行為 DataControlFieldCollectionA StateManagedCollection object influences the behavior of a DataControlFieldCollection object. DataControlField當還原狀態時,會將動態新增至集合的物件重新加入至控制項。DataControlField objects that are dynamically added to the collection will be re-added to the control when state is restored. 這表示欄位只需要加入、移除或變更一次,而不是在每次回傳時,因為 ASP.NET 中的大部分集合類型都需要。This means that a field needs to be added, removed, or changed just once instead of on each postback, as most collection types in ASP.NET require.

(DataControlField 類別會實作為 IStateManager 介面,讓它能夠以 ASP.NET 檢視狀態儲存其狀態。(The DataControlField class implements the IStateManager interface, which enables it to store its state in ASP.NET view state. ))

使用 DataControlFieldCollection 類別,以程式設計方式管理一組 DataControlField 物件。Use the DataControlFieldCollection class to programmatically manage a set of DataControlField objects. 請注意,以宣告方式定義這些欄位較為常見。Note that it is more common to define these fields declaratively.

您可以使用類別的適當方法來新增、插入和移除 DataControlField 物件 DataControlFieldCollectionYou can add, insert, and remove DataControlField objects using the appropriate methods of the DataControlFieldCollection class. 若要以程式設計方式 DataControlField 從集合中取出物件,請使用下列其中一種方法:To programmatically retrieve DataControlField objects from a collection, use one of following methods:

Count屬性會指定集合中的專案總數,而且通常用來判斷集合的上限。The Count property specifies the total number of items in the collection, and is commonly used to determine the upper bound of the collection. 您可以使用 Add 、、 Insert Remove 和方法,在集合中加入和移除專案 RemoveAtYou can add items to and remove items from the collection using the Add, Insert, Remove, and RemoveAt methods.

如果您使用 GridViewDetailsView 控制項,則會 DataControlField 自動建立的物件 (例如,當 AutoGenerateColumns 屬性 true) 不會儲存在可公開存取的 fields 集合中。If you are using the GridView or DetailsView control, the DataControlField objects that are automatically created (for example, when the AutoGenerateColumns property is true) are not stored in the publicly accessible fields collection. 您只能存取並操作 DataControlField 不會自動產生的物件。You can only access and manipulate DataControlField objects that are not automatically generated.

下表列出不同的資料控制欄位類別,以及它們的使用方式。The following table lists the different data control field classes and how they are used.

參數類別Parameter Class 描述Description
DataControlField 所有欄位的抽象基類。The abstract base class for all fields.
BoundField 資料繫結控制項欄位,用來系結至從 ASP.NET 資料來源控制項抓取的文字或資料。A data-bound control field that is used to bind to text or data retrieved from an ASP.NET data source control.
ButtonFieldBase 封裝一般按鈕功能的資料繫結控制項欄位。A data-bound control field that encapsulates general button functionality. ButtonFieldCheckBoxField 衍生自它。ButtonField and CheckBoxField are derived from it.
ButtonField 至少顯示一個按鈕的資料繫結控制項欄位。A data-bound control field that displays at least one button.
CheckBoxField 顯示控制項的資料繫結控制項欄位 CheckBoxA data-bound control field that displays a CheckBox control.
CommandField 資料繫結控制項欄位,會顯示可在資料列 (或資料行) (例如編輯、更新或刪除)所顯示的資料上執行的動作。A data-bound control field that displays actions that can be performed on the data displayed by the row (or column), such as edit, update, or delete.
HyperLinkField 顯示控制項的資料繫結控制項欄位 HyperLinkA data-bound control field that displays a HyperLink control.
ImageField 顯示控制項的資料繫結控制項欄位 ImageA data-bound control field that displays an Image control.
TemplateField 資料繫結控制項欄位,會顯示資料繫結控制項中的自訂內容。A data-bound control field that displays custom content in a data-bound control.

建構函式

DataControlFieldCollection()

初始化 DataControlFieldCollection 類別的新執行個體。Initializes a new instance of the DataControlFieldCollection class.

屬性

Count

取得 StateManagedCollection 集合中所包含的項目數。Gets the number of elements contained in the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
Item[Int32]

取得或設定位於集合中所指定索引處的 DataControlField 物件。Gets or sets the DataControlField object at the specified index in the collection.

方法

Add(DataControlField)

將指定的 DataControlField 物件附加到集合的結尾。Appends the specified DataControlField object to the end of the collection.

Clear()

將所有項目從 StateManagedCollection 集合中移除。Removes all items from the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
CloneFields()

建立目前集合的複本。Creates a copy of the current collection.

Contains(DataControlField)

判斷 DataControlFieldCollection 集合是否含有特定 DataControlField 物件。Determines whether the DataControlFieldCollection collection contains a specific DataControlField object.

CopyTo(Array, Int32)

從特定的陣列索引開始,將 StateManagedCollection 集合的項目複製到陣列。Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index.

(繼承來源 StateManagedCollection)
CopyTo(DataControlField[], Int32)

從目標陣列的指定之索引開始,將整個 DataControlFieldCollection 集合複製到相容的一維 ArrayCopies the entire DataControlFieldCollection collection to a compatible one-dimensional Array, starting at the specified index of the target array.

CreateKnownType(Int32)

在衍生類別中覆寫時,建立實作 IStateManager 之類別的執行個體。When overridden in a derived class, creates an instance of a class that implements IStateManager. 根據 GetKnownTypes() 方法所傳回之集合指定的成員,建立物件的類型。The type of object created is based on the specified member of the collection returned by the GetKnownTypes() method.

(繼承來源 StateManagedCollection)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。Returns an iterator that iterates through the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetKnownTypes()

在衍生類別中覆寫時,取得 StateManagedCollection 集合可以包含之 IStateManager 類型的陣列。When overridden in a derived class, gets an array of IStateManager types that the StateManagedCollection collection can contain.

(繼承來源 StateManagedCollection)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IndexOf(DataControlField)

判斷集合中特定 DataControlField 物件的索引。Determines the index of a specific DataControlField object in the collection.

Insert(Int32, DataControlField)

將指定的 DataControlField 物件插入 DataControlFieldCollection 集合中的指定索引處。Inserts the specified DataControlField object into the DataControlFieldCollection collection at the specified index.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnClear()

在衍生類別中覆寫時,在 Clear() 方法移除集合的所有項目之前,執行額外工作。When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection.

(繼承來源 StateManagedCollection)
OnClearComplete()

在衍生類別中覆寫時,在 Clear() 方法完成移除集合的所有項目之後,執行額外工作。When overridden in a derived class, performs additional work after the Clear() method finishes removing all items from the collection.

(繼承來源 StateManagedCollection)
OnInsert(Int32, Object)

在衍生類別中覆寫時,在 IList.Insert(Int32, Object)IList.Add(Object) 方法將項目加入集合之前,執行額外工作。When overridden in a derived class, performs additional work before the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection.

(繼承來源 StateManagedCollection)
OnInsertComplete(Int32, Object)

在衍生類別中覆寫時,在 IList.Insert(Int32, Object)IList.Add(Object) 方法將項目加入集合之後,執行額外工作。When overridden in a derived class, performs additional work after the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection.

(繼承來源 StateManagedCollection)
OnRemove(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之前,執行額外工作。When overridden in a derived class, performs additional work before the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(繼承來源 StateManagedCollection)
OnRemoveComplete(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之後,執行額外工作。When overridden in a derived class, performs additional work after the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(繼承來源 StateManagedCollection)
OnValidate(Object)

在衍生類別中覆寫時,驗證 StateManagedCollection 集合的項目。When overridden in a derived class, validates an element of the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
Remove(DataControlField)

DataControlField 集合中移除指定的 DataControlFieldCollection 物件。Removes the specified DataControlField object from the DataControlFieldCollection collection.

RemoveAt(Int32)

DataControlField 集合中移除指定索引處的 DataControlFieldCollection 物件。Removes the DataControlField object at the specified index from the DataControlFieldCollection collection.

SetDirty()

強制整個 StateManagedCollection 集合序列化至檢視狀態。Forces the entire StateManagedCollection collection to be serialized into view state.

(繼承來源 StateManagedCollection)
SetDirtyObject(Object)

在衍生類別中覆寫時,指示集合中所包含的 object,將其完整狀態 (而不只是變更資訊) 記錄至檢視狀態。When overridden in a derived class, instructs an object contained by the collection to record its entire state to view state, rather than recording only change information.

(繼承來源 StateManagedCollection)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

FieldsChanged

當集合中的欄位變更時發生,通常做為 Clear()Insert(Int32, DataControlField)Remove(DataControlField)Add(DataControlField) 方法呼叫的結果。Occurs when the fields in the collection change, usually as the result of a Clear(), Insert(Int32, DataControlField), Remove(DataControlField) or Add(DataControlField) method call. 只要集合中的 DataControlField 引發其 FieldChanged 事件,也會引發這個事件。This event is also raised anytime a DataControlField in the collection raises its FieldChanged event.

明確介面實作

ICollection.Count

取得 StateManagedCollection 集合中所包含的項目數。Gets the number of elements contained in the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
ICollection.IsSynchronized

取得值,表示 StateManagedCollection 集合是否為同步 (安全執行緒)。Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). 在所有情況下,這個方法都會傳回 falseThis method returns false in all cases.

(繼承來源 StateManagedCollection)
ICollection.SyncRoot

取得物件,可用來同步處理對 StateManagedCollection 集合的存取。Gets an object that can be used to synchronize access to the StateManagedCollection collection. 在所有情況下,這個方法都會傳回 nullThis method returns null in all cases.

(繼承來源 StateManagedCollection)
IEnumerable.GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。Returns an iterator that iterates through the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
IList.Add(Object)

將項目加入 StateManagedCollection 集合。Adds an item to the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
IList.Clear()

將所有項目從 StateManagedCollection 集合中移除。Removes all items from the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
IList.Contains(Object)

判斷 StateManagedCollection 集合是否包含特定值。Determines whether the StateManagedCollection collection contains a specific value.

(繼承來源 StateManagedCollection)
IList.IndexOf(Object)

判斷 StateManagedCollection 集合中指定之項目的索引。Determines the index of a specified item in the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
IList.Insert(Int32, Object)

將項目插入位於指定索引處的 StateManagedCollection 集合中。Inserts an item into the StateManagedCollection collection at the specified index.

(繼承來源 StateManagedCollection)
IList.IsFixedSize

取得值,表示 StateManagedCollection 集合是否具有固定大小。Gets a value indicating whether the StateManagedCollection collection has a fixed size. 在所有情況下,這個方法都會傳回 falseThis method returns false in all cases.

(繼承來源 StateManagedCollection)
IList.IsReadOnly

取得值,表示 StateManagedCollection 集合是否為唯讀。Gets a value indicating whether the StateManagedCollection collection is read-only.

(繼承來源 StateManagedCollection)
IList.Item[Int32]

取得指定索引處的 IStateManager 項目。Gets the IStateManager element at the specified index.

(繼承來源 StateManagedCollection)
IList.Remove(Object)

StateManagedCollection 集合中移除指定物件的第一個符合項目。Removes the first occurrence of the specified object from the StateManagedCollection collection.

(繼承來源 StateManagedCollection)
IList.RemoveAt(Int32)

移除指定索引處的 IStateManager 項目。Removes the IStateManager element at the specified index.

(繼承來源 StateManagedCollection)
IStateManager.IsTrackingViewState

取得值,表示 StateManagedCollection 集合是否正在儲存變更至檢視狀態。Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state.

(繼承來源 StateManagedCollection)
IStateManager.LoadViewState(Object)

還原先前儲存之 StateManagedCollection 集合和內含 IStateManager 項目的檢視狀態。Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains.

(繼承來源 StateManagedCollection)
IStateManager.SaveViewState()

儲存自頁面回傳至伺服器以來 StateManagedCollection 集合和每個內含 IStateManager 物件的變更。Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server.

(繼承來源 StateManagedCollection)
IStateManager.TrackViewState()

使得 StateManagedCollection 集合和每個內含 IStateManager 物件追蹤其檢視狀態的變更,以便跨相同頁面要求保存這些變更。Causes the StateManagedCollection collection and each of the IStateManager objects it contains to track changes to their view state so they can be persisted across requests for the same page.

(繼承來源 StateManagedCollection)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱