WebPartCollection.Item Property (Int32)
Assembly: System.Web (in system.web.dll)
/** @property */ public WebPart get_Item (int index)
JScript supports the use of indexed properties, but not the declaration of new ones.
Parameters
- index
The index of a particular WebPart control in a collection.
Property Value
A WebPart at the specified index in the collection.The Item indexer allows you to access the underlying WebPart controls in a WebPartCollection object by index, and change their property values or call methods.
The following code example demonstrates the use of the Item indexer on a Web Parts page. This example has three parts:
-
The code for the page in a partial class.
-
The Web page that contains the controls.
-
A description of how the example works in a browser.
The first part of the code example contains the code for the page in a partial class. Note that the Button2_Click method creates an empty WebPartCollection object, then assigns to it the WebPart controls from the WebPartZone1.WebParts property. The method accesses the first control in the collection by using its index, and toggles its Title property value.
The second part of the code example is the Web page that contains the controls. Notice that the controls declared in WebPartZone1 are standard ASP.NET server controls, but because they are wrapped as GenericWebPart controls at run time, and the GenericWebPart class inherits from the WebPart class, the controls can be treated as WebPart controls at run time and made part of a WebPartCollection object.
After you load the page in a browser, click the Toggle BulletedList1 Title button, and notice that the code toggles the title of the control between the two available title choices.
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.