通过


ControlCollection.Count 属性

定义

获取指定 ASP.NET 服务器控件的对象 ControlCollection 中的服务器控件数。

public:
 property int Count { int get(); };
public:
 virtual property int Count { int get(); };
public int Count { get; }
public virtual int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer
Public Overridable ReadOnly Property Count As Integer

属性值

中的 ControlCollection服务器控件数。

实现

示例

下面的代码示例演示如何使用 Count 属性循环访问控件的对象 ControlCollection 。 属性的使用 Control.HasControls() 验证控件是否具有子控件。 如果 Control.HasControls 返回 false,则剩余的代码不会运行。

if (HasControls()) {
                 for (int i=0; i < Controls.Count; i++) {
                     Controls[i].RenderControl(writer);
                 }
   }
If HasControls() Then
    Dim i As Integer
    For i = 0 To Controls.Count - 1
        Controls(i).RenderControl(writer)
    Next i
End If

适用于

另请参阅