Editar

Compartilhar via


DataControlFieldCollection Class

Definition

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
Inheritance
DataControlFieldCollection

Remarks

The DataControlFieldCollection class represents a collection of DataControlField objects used by data-bound controls to specify how their child controls are presented. The DataControlFieldCollection class derives from StateManagedCollection, an abstract base collection class used specifically to store IStateManager objects.

A StateManagedCollection object influences the behavior of a DataControlFieldCollection object. DataControlField objects that are dynamically added to the collection will be re-added to the control when state is restored. 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.

(The DataControlField class implements the IStateManager interface, which enables it to store its state in ASP.NET view state. )

Use the DataControlFieldCollection class to programmatically manage a set of DataControlField objects. Note that it is more common to define these fields declaratively.

You can add, insert, and remove DataControlField objects using the appropriate methods of the DataControlFieldCollection class. To programmatically retrieve DataControlField objects from a collection, use one of following methods:

The Count property specifies the total number of items in the collection, and is commonly used to determine the upper bound of the collection. You can add items to and remove items from the collection using the Add, Insert, Remove, and RemoveAt methods.

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. 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 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. ButtonField and CheckBoxField are derived from it.
ButtonField A data-bound control field that displays at least one button.
CheckBoxField A 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 A data-bound control field that displays a HyperLink control.
ImageField A data-bound control field that displays an Image control.
TemplateField A data-bound control field that displays custom content in a data-bound control.

Constructors

DataControlFieldCollection()

Initializes a new instance of the DataControlFieldCollection class.

Properties

Count

Gets the number of elements contained in the StateManagedCollection collection.

(Inherited from StateManagedCollection)
Item[Int32]

Gets or sets the DataControlField object at the specified index in the collection.

Methods

Add(DataControlField)

Appends the specified DataControlField object to the end of the collection.

Clear()

Removes all items from the StateManagedCollection collection.

(Inherited from StateManagedCollection)
CloneFields()

Creates a copy of the current collection.

Contains(DataControlField)

Determines whether the DataControlFieldCollection collection contains a specific DataControlField object.

CopyTo(Array, Int32)

Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index.

(Inherited from StateManagedCollection)
CopyTo(DataControlField[], Int32)

Copies the entire DataControlFieldCollection collection to a compatible one-dimensional Array, starting at the specified index of the target array.

CreateKnownType(Int32)

When overridden in a derived class, creates an instance of a class that implements IStateManager. The type of object created is based on the specified member of the collection returned by the GetKnownTypes() method.

(Inherited from StateManagedCollection)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Returns an iterator that iterates through the StateManagedCollection collection.

(Inherited from StateManagedCollection)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetKnownTypes()

When overridden in a derived class, gets an array of IStateManager types that the StateManagedCollection collection can contain.

(Inherited from StateManagedCollection)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(DataControlField)

Determines the index of a specific DataControlField object in the collection.

Insert(Int32, DataControlField)

Inserts the specified DataControlField object into the DataControlFieldCollection collection at the specified index.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnClear()

When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection.

(Inherited from StateManagedCollection)
OnClearComplete()

When overridden in a derived class, performs additional work after the Clear() method finishes removing all items from the collection.

(Inherited from StateManagedCollection)
OnInsert(Int32, 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.

(Inherited from StateManagedCollection)
OnInsertComplete(Int32, 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.

(Inherited from StateManagedCollection)
OnRemove(Int32, Object)

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.

(Inherited from StateManagedCollection)
OnRemoveComplete(Int32, Object)

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.

(Inherited from StateManagedCollection)
OnValidate(Object)

When overridden in a derived class, validates an element of the StateManagedCollection collection.

(Inherited from StateManagedCollection)
Remove(DataControlField)

Removes the specified DataControlField object from the DataControlFieldCollection collection.

RemoveAt(Int32)

Removes the DataControlField object at the specified index from the DataControlFieldCollection collection.

SetDirty()

Forces the entire StateManagedCollection collection to be serialized into view state.

(Inherited from StateManagedCollection)
SetDirtyObject(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.

(Inherited from StateManagedCollection)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

FieldsChanged

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. This event is also raised anytime a DataControlField in the collection raises its FieldChanged event.

Explicit Interface Implementations

ICollection.Count

Gets the number of elements contained in the StateManagedCollection collection.

(Inherited from StateManagedCollection)
ICollection.IsSynchronized

Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). This method returns false in all cases.

(Inherited from StateManagedCollection)
ICollection.SyncRoot

Gets an object that can be used to synchronize access to the StateManagedCollection collection. This method returns null in all cases.

(Inherited from StateManagedCollection)
IEnumerable.GetEnumerator()

Returns an iterator that iterates through the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Add(Object)

Adds an item to the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Clear()

Removes all items from the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Contains(Object)

Determines whether the StateManagedCollection collection contains a specific value.

(Inherited from StateManagedCollection)
IList.IndexOf(Object)

Determines the index of a specified item in the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.Insert(Int32, Object)

Inserts an item into the StateManagedCollection collection at the specified index.

(Inherited from StateManagedCollection)
IList.IsFixedSize

Gets a value indicating whether the StateManagedCollection collection has a fixed size. This method returns false in all cases.

(Inherited from StateManagedCollection)
IList.IsReadOnly

Gets a value indicating whether the StateManagedCollection collection is read-only.

(Inherited from StateManagedCollection)
IList.Item[Int32]

Gets the IStateManager element at the specified index.

(Inherited from StateManagedCollection)
IList.Remove(Object)

Removes the first occurrence of the specified object from the StateManagedCollection collection.

(Inherited from StateManagedCollection)
IList.RemoveAt(Int32)

Removes the IStateManager element at the specified index.

(Inherited from StateManagedCollection)
IStateManager.IsTrackingViewState

Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state.

(Inherited from StateManagedCollection)
IStateManager.LoadViewState(Object)

Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains.

(Inherited from StateManagedCollection)
IStateManager.SaveViewState()

Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server.

(Inherited from StateManagedCollection)
IStateManager.TrackViewState()

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.

(Inherited from StateManagedCollection)

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also