ControlCollection 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供使 ASP.NET 服务器控件能够维护其子控件列表的集合容器。
public ref class ControlCollection : System::Collections::ICollection
	public class ControlCollection : System.Collections.ICollection
	type ControlCollection = class
    interface ICollection
    interface IEnumerable
	Public Class ControlCollection
Implements ICollection
		- 继承
 - 
				ControlCollection
 
- 派生
 
- 实现
 
示例
下面的代码示例重写 Control.CreateChildControls 方法以创建两个控件,这两个控件都是名为 ChildControl的自定义类的实例,该类具有名为 的 Message字符串属性。 创建后,这两个控件将添加到 。ControlCollection 
              Add对每个控件调用 方法,以将它们添加到包含此版本的 类Control.CreateChildControls中。 属性 ChildControlsCreated 设置为 true ,这样就不会不必要地再次创建这些控件。
protected override void CreateChildControls()
{               
   // Creates a new ControlCollection. 
   this.CreateControlCollection();
   // Create child controls.
    ChildControl firstControl = new ChildControl();
   firstControl.Message = "FirstChildControl";
   ChildControl secondControl = new ChildControl();
   secondControl.Message = "SecondChildControl";
   
   Controls.Add(firstControl);
   Controls.Add(secondControl);
   // Prevent child controls from being created again.
   ChildControlsCreated = true;
}
Protected Overrides Sub CreateChildControls()
   ' Creates a new ControlCollection. 
   Me.CreateControlCollection()
   
   ' Create child controls.
   Dim firstControl As New ChildControl()
   firstControl.Message = "FirstChildControl"
   
   Dim secondControl As New ChildControl()
   secondControl.Message = "SecondChildControl"
   
   Controls.Add(firstControl)
   Controls.Add(secondControl)
   
   ' Prevent child controls from being created again.
   ChildControlsCreated = True
End Sub
	注解
可以通过 属性访问 类Control.Controls的任何属性和方法ControlCollection。 由于 类 Control 是所有 ASP.NET 服务器控件的基类,因此所有服务器控件都继承此属性。
有关集合的详细信息,请参阅 集合和数据结构。
构造函数
| ControlCollection(Control) | 
		 为指定的父服务器控件初始化 ControlCollection 类的新实例。  | 
        	
属性
| Count | 
		 为指定的 ASP.NET 服务器控件获取 ControlCollection 对象中的服务器控件数。  | 
        	
| IsReadOnly | 
		 获取一个值,该值指示 ControlCollection 对象是否为只读。  | 
        	
| IsSynchronized | 
		 获取一个值,该值指示是否同步 ControlCollection 对象。  | 
        	
| Item[Int32] | 
		 获取对 ControlCollection 对象中指定索引位置的服务器控件的引用。  | 
        	
| Owner | 
		 获取 ControlCollection 对象所属的 ASP.NET 服务器控件。  | 
        	
| SyncRoot | 
		 获取可用于同步控件集合访问的对象。  | 
        	
方法
| Add(Control) | 
		 将指定的 Control 对象添加到集合。  | 
        	
| AddAt(Int32, Control) | 
		 将指定的 Control 对象添加到集合中的指定索引位置。  | 
        	
| Clear() | 
		 从当前服务器控件的 ControlCollection 对象中移除所有控件。  | 
        	
| Contains(Control) | 
		 确定指定的服务器控件是否在父服务器控件的 ControlCollection 对象中。  | 
        	
| CopyTo(Array, Int32) | 
		 从 ControlCollection 中的指定索引位置开始,将 Array 对象中存储的子控件复制到 Array 对象。  | 
        	
| Equals(Object) | 
		 确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetEnumerator() | 
		 检索可遍历 ControlCollection 对象的枚举器。  | 
        	
| GetHashCode() | 
		 作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| IndexOf(Control) | 
		 检索集合中指定 Control 对象的索引。  | 
        	
| MemberwiseClone() | 
		 创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| Remove(Control) | 
		 从父服务器控件的 ControlCollection 对象中移除指定服务器控件。  | 
        	
| RemoveAt(Int32) | 
		 从 ControlCollection 对象中移除指定索引位置处的子控件。  | 
        	
| ToString() | 
		 返回表示当前对象的字符串。 (继承自 Object) | 
        	
扩展方法
| Cast<TResult>(IEnumerable) | 
		 将 IEnumerable 的元素强制转换为指定的类型。  | 
        	
| OfType<TResult>(IEnumerable) | 
		 根据指定类型筛选 IEnumerable 的元素。  | 
        	
| AsParallel(IEnumerable) | 
		 启用查询的并行化。  | 
        	
| AsQueryable(IEnumerable) | 
		 将 IEnumerable 转换为 IQueryable。  |