WebPartCollection.Item[] Propriedade
Definição
Retorna um membro específico da coleção de acordo com sua posição ou com um identificador exclusivo.Returns a specific member of the collection according to its position or a unique identifier.
Sobrecargas
| Item[Int32] |
Retorna um membro da coleção com base em sua posição na coleção.Returns a member of the collection based on its position in the collection. |
| Item[String] |
Retorna um membro da coleção com base em um identificador de cadeia de caracteres exclusivo.Returns a member of the collection based on a unique string identifier. |
Item[Int32]
Retorna um membro da coleção com base em sua posição na coleção.Returns a member of the collection based on its position in the collection.
public:
property System::Web::UI::WebControls::WebParts::WebPart ^ default[int] { System::Web::UI::WebControls::WebParts::WebPart ^ get(int index); };
public System.Web.UI.WebControls.WebParts.WebPart this[int index] { get; }
member this.Item(int) : System.Web.UI.WebControls.WebParts.WebPart
Default Public ReadOnly Property Item(index As Integer) As WebPart
Parâmetros
- index
- Int32
O índice de um determinado controle WebPart em uma coleção.The index of a particular WebPart control in a collection.
Valor da propriedade
Um WebPart no índice especificado na coleção.A WebPart at the specified index in the collection.
Exemplos
O exemplo de código a seguir demonstra o uso do Item[] indexador em uma página Web Parts.The following code example demonstrates the use of the Item[] indexer on a Web Parts page. Este exemplo tem três partes:This example has three parts:
O código para a página em uma classe parcial.The code for the page in a partial class.
A página da Web que contém os controles.The Web page that contains the controls.
Uma descrição de como o exemplo funciona em um navegador.A description of how the example works in a browser.
A primeira parte do exemplo de código contém o código para a página em uma classe parcial.The first part of the code example contains the code for the page in a partial class. Observe que o Button2_Click método cria um WebPartCollection objeto vazio e, em seguida, atribui a ele os WebPart controles da WebPartZone1.WebParts propriedade.Note that the Button2_Click method creates an empty WebPartCollection object, then assigns to it the WebPart controls from the WebPartZone1.WebParts property. O método acessa o primeiro controle na coleção usando seu índice e alterna o Title valor da propriedade.The method accesses the first control in the collection by using its index, and toggles its Title property value.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class webpartcollectioncs : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
WebPartCollection partCollection = mgr1.WebParts;
foreach (WebPart part in partCollection)
{
if (part.ChromeState != PartChromeState.Minimized)
part.ChromeState = PartChromeState.Minimized;
else
part.ChromeState = PartChromeState.Normal;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
WebPartCollection partCollection = WebPartZone1.WebParts;
if (partCollection[0].Title == "My Link List")
partCollection[0].Title = "Favorite Links";
else
partCollection[0].Title = "My Link List";
}
}
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Partial Public Class webpartcollectionvb
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim partCollection As WebPartCollection = mgr1.WebParts
Dim part As WebPart
For Each part In partCollection
If part.ChromeState <> PartChromeState.Minimized Then
part.ChromeState = PartChromeState.Minimized
Else
part.ChromeState = PartChromeState.Normal
End If
Next
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim partCollection As WebPartCollection = WebPartZone1.WebParts
If partCollection(0).Title = "My Link List" Then
partCollection(0).Title = "Favorite Links"
Else
partCollection(0).Title = "My Link List"
End If
End Sub
End Class
A segunda parte do exemplo de código é a página da Web que contém os controles.The second part of the code example is the Web page that contains the controls. Observe que os controles declarados no WebPartZone1 são controles de servidor ASP.NET padrão, mas como são encapsulados como GenericWebPart controles em tempo de execução e a GenericWebPart classe herda da WebPart classe, os controles podem ser tratados como WebPart controles em tempo de execução e fazem parte de um WebPartCollection objeto.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.
<%@ Page Language="C#"
Codefile="webpartcollection.cs"
Inherits="webpartcollectioncs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="mgr1" runat="server" />
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:BulletedList
ID="BulletedList1"
Runat="server"
DisplayMode="HyperLink"
Title="Favorite Links" >
<asp:ListItem Value="http://msdn.microsoft.com">
MSDN
</asp:ListItem>
<asp:ListItem Value="http://www.asp.net">
ASP.NET
</asp:ListItem>
<asp:ListItem Value="http://www.msn.com">
MSN
</asp:ListItem>
</asp:BulletedList>
<br />
<asp:Calendar ID="Calendar1" runat="server"
Title="My Calendar" />
</ZoneTemplate>
</asp:WebPartZone>
</div>
<hr />
<asp:Button ID="Button1" runat="server" Width="200"
Text="Toggle ChromeState" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Width="200"
Text="Toggle BulletedList1 Title"
OnClick="Button2_Click"/>
</form>
</body>
</html>
<%@ Page Language="vb"
Codefile="webpartcollection.vb"
Inherits="webpartcollectionvb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="mgr1" runat="server" />
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:BulletedList
ID="BulletedList1"
Runat="server"
DisplayMode="HyperLink"
Title="Favorite Links" >
<asp:ListItem Value="http://msdn.microsoft.com">
MSDN
</asp:ListItem>
<asp:ListItem Value="http://www.asp.net">
ASP.NET
</asp:ListItem>
<asp:ListItem Value="http://www.msn.com">
MSN
</asp:ListItem>
</asp:BulletedList>
<br />
<asp:Calendar ID="Calendar1" runat="server"
Title="My Calendar" />
</ZoneTemplate>
</asp:WebPartZone>
</div>
<hr />
<asp:Button ID="Button1" runat="server" Width="200"
Text="Toggle ChromeState" OnClick="Button1_Click" />
<br />
<asp:Button ID="Button2" runat="server" Width="200"
Text="Toggle BulletedList1 Title"
OnClick="Button2_Click"/>
</form>
</body>
</html>
Depois de carregar a página em um navegador, clique no botão alternar título do BulletedList1 e observe que o código alterna o título do controle entre as duas opções de título disponíveis.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.
Comentários
O Item[] indexador permite que você acesse os WebPart controles subjacentes em um WebPartCollection objeto por índice e altere seus valores de propriedade ou chame métodos.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.
Confira também
Aplica-se a
Item[String]
Retorna um membro da coleção com base em um identificador de cadeia de caracteres exclusivo.Returns a member of the collection based on a unique string identifier.
public:
property System::Web::UI::WebControls::WebParts::WebPart ^ default[System::String ^] { System::Web::UI::WebControls::WebParts::WebPart ^ get(System::String ^ id); };
public System.Web.UI.WebControls.WebParts.WebPart this[string id] { get; }
member this.Item(string) : System.Web.UI.WebControls.WebParts.WebPart
Default Public ReadOnly Property Item(id As String) As WebPart
Parâmetros
- id
- String
O identificador exclusivo para um controle WebPart específico em uma coleção.The unique identifier for a particular WebPart control in a collection.
Valor da propriedade
O primeiro WebPart na coleção cuja ID é igual ao valor de id .The first WebPart in the collection whose ID equals the value of id.
Comentários
O Item[] indexador permite que você acesse um WebPart controle em um WebPartCollection objeto de acordo com um identificador exclusivo.The Item[] indexer enables you to access a WebPart control in a WebPartCollection object according to a unique identifier.
Observação
O conjunto de controle de Web Parts executa correspondência que não diferencia maiúsculas de minúsculas nessa propriedade, portanto, a distinção de maiúsculas e minúsculas não faz parte de um id valor exclusivo.The Web Parts control set performs case-insensitive matching on this property, so case sensitivity is not part of a unique id value.
A Item[] propriedade também funciona para identificar membros de um WebPartCollection objeto em alguns casos especializados.The Item[] property also works to identify members of a WebPartCollection object in some specialized cases. No caso de GenericWebPart controles, o indexador é capaz de corresponder ao identificador do controle filho subjacente encapsulado pelo GenericWebPart controle.In the case of GenericWebPart controls, the indexer is able to match the identifier for the underlying child control wrapped by the GenericWebPart control. No caso de ProxyWebPart controles, o indexador corresponde ao identificador do controle com base em uma comparação que não diferencia maiúsculas de minúsculas do id parâmetro e OriginalID dos GenericWebPartID valores de propriedade ou.In the case of ProxyWebPart controls, the indexer matches the identifier for the control based on a case-insensitive comparison of the id parameter and either the OriginalID or GenericWebPartID property values.