ControlCollection.Item Property

Gets a reference to the server control at the specified index location in the ControlCollection object.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public:
virtual property Control^ default [int] {
	Control^ get (int index);
}
/** @property */
public Control get_Item (int index)

Not applicable.

Parameters

index

The location of the server control in the ControlCollection.

Property Value

The reference to the control.

Exception typeCondition

ArgumentOutOfRangeException

The index parameter is less than zero or greater than or equal to ControlCollection.Count.

The following code example uses the Item property to specify the index location of a child control that is removed in a Remove method call. This is performed by the myButton.Controls.Remove syntax.

No code example is currently available or this language may not be supported.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    void Page_Load(Object Sender, EventArgs e)
    {
        get_Response().Write(
            "<h2>Sample for ControlCollection Class</h2>");
        
        LiteralControl myLiteralControl =  
            new LiteralControl("ChildControl1");
        myButton.get_Controls().Add(myLiteralControl);
        myButton.get_Controls().AddAt(1, 
            new LiteralControl("ChildControl2"));

        System.Array myControlCollectionArray = 
            Array.CreateInstance(
                Object.class.ToType(), 
                myButton.get_Controls().get_Count());
        myButton.get_Controls().CopyTo(myControlCollectionArray, 0);
        
        IEnumerator myEnumerator1 = 
            myControlCollectionArray.GetEnumerator();
        
        while(myEnumerator1.MoveNext()) 
        {
            Object myObject = myEnumerator1.get_Current();
            if (myObject.GetType().Equals(
                LiteralControl.class.ToType())) 
            {
                LiteralControl childControl = 
                    ((LiteralControl)(myEnumerator1.
                    get_Current()));
                get_Response().Write(
                    "<p style=\"font-weight:bold\"><br />");
                get_Response().Write("The count of ControlCollection = ");
                get_Response().Write(get_Server().HtmlEncode(
                    childControl.get_Text()) + "</p>");
            }
        }
        myButton.get_Controls().Remove(
            myButton.get_Controls().get_Item(0));
        get_Response().Write(
            "<br /><b>ChildControl1 is removed</b>");
        get_Response().Write(
            "<br /><b> The count of ControlCollection </b>" 
            + myButton.get_Controls().get_Count());
        myButton.get_Controls().Clear();
    } //Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Sample for ControlCollection Class</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="myButton" Text="Sample ServerControl" 
            Runat="server"></asp:Button>

    </div>
    </form>
</body>
</html>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: