This documentation is archived and is not being maintained.

ControlCollection.Count Property

Gets the number of server controls in the ControlCollection object for the specified ASP.NET server control.

[Visual Basic]
Public Overridable ReadOnly Property Count As Integer  Implements _
   ICollection.Count
[C#]
public virtual int Count {get;}
[C++]
public: __property virtual int get_Count();
[JScript]
public function get Count() : int;

Property Value

The number of server controls in the ControlCollection object.

Implements

ICollection.Count

Example

The following example demonstrates how to use the Count property to iterate through a control's ControlCollection object. The use of the Control.HasControls property verifies that the control has child controls. If HasControls returns false, the remaining code does not run.

[Visual Basic] 
If HasControls() Then
    Dim i As Integer
    For i = 0 To Controls.Count - 1
        Controls(i).RenderControl(writer)
    Next i
End If

[C#] 
if (HasControls()) {
                 for (int i=0; i < Controls.Count; i++) {
                     Controls[i].RenderControl(writer);
                 }
   }

[C++] 
if (HasControls()) {
   for (int i=0; i < Controls->Count; i++) {
      Controls->Item[i]->RenderControl(writer);
   }
}

[JScript] 
if (HasControls()) {
                 for (var i : int = 0; i < Controls.Count; i++) {
                     Controls[i].RenderControl(writer);
                 }
   }

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

ControlCollection Class | ControlCollection Members | System.Web.UI Namespace | Controls

Show: