EditorPartCollection.IndexOf(EditorPart) Metodo

Definizione

Restituisce la posizione di un membro specifico dell'insieme.

public:
 int IndexOf(System::Web::UI::WebControls::WebParts::EditorPart ^ editorPart);
public int IndexOf (System.Web.UI.WebControls.WebParts.EditorPart editorPart);
member this.IndexOf : System.Web.UI.WebControls.WebParts.EditorPart -> int
Public Function IndexOf (editorPart As EditorPart) As Integer

Parametri

editorPart
EditorPart

Oggetto EditorPart che corrisponde a un membro dell'insieme.

Restituisce

Integer che corrisponde all'indice di un controllo EditorPart nell'insieme.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare il IndexOf metodo per individuare un EditorPart controllo in un EditorPartCollection oggetto . Per il codice completo necessario per eseguire l'esempio, vedere la sezione Esempio della panoramica della EditorPartCollection classe.

Il codice nell'evento Button1_Click crea un EditorPartCollection oggetto e quindi usa il IndexOf metodo per individuare il controllo nell'insieme e impostarne la PropertyGridEditorPart1ChromeType proprietà.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    ArrayList list = new ArrayList(2);
    list.Add(AppearanceEditorPart1);
    list.Add(PropertyGridEditorPart1);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
    {
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";
    }

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
    if(!myParts.Contains(LayoutEditorPart1))
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;
    
    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    myParts.CopyTo(partArray,1);
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
    {
      Label1.Text += ePart.Title + "<br />";
    }

  }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    Dim list As New ArrayList(2)
    list.Add(AppearanceEditorPart1)
    list.Add(PropertyGridEditorPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New EditorPartCollection(list)
    Dim editor As EditorPart
    For Each editor In myParts
      editor.BackColor = System.Drawing.Color.LightBlue
      editor.Description = "My " + editor.DisplayTitle + " editor."
    Next editor
    
    ' Use the IndexOf property to locate an EditorPart control.
    Dim propertyGridPart As Integer = _
      myParts.IndexOf(PropertyGridEditorPart1)
    myParts(propertyGridPart).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if an EditorPart exists.
    If Not myParts.Contains(LayoutEditorPart1) Then
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow
    End If
    
    ' Use the CopyTo method to create an array of EditorParts.
    Dim partArray(2) As EditorPart
    partArray(0) = LayoutEditorPart1
    myParts.CopyTo(partArray, 1)
    Label1.Text = "<h3>EditorParts in Custom Array</h3>"
    Dim ePart As EditorPart
    For Each ePart In partArray
      Label1.Text += ePart.Title + "<br />"
    Next ePart

  End Sub

</script>

Quando si carica la pagina in un browser, è possibile passare alla modalità di modifica selezionando Modifica nel controllo elenco a discesa Modalità di visualizzazione . È possibile fare clic sul menu dei verbi (freccia verso il basso) nella barra del titolo del TextDisplayWebPart controllo e fare clic su Modifica per modificare il controllo. Quando l'interfaccia utente di modifica è visibile, è possibile visualizzare tutti i EditorPart controlli. Se si fa clic sul pulsante Crea EditorPartCollection , si noterà che il PropertyGridEditorPart1 controllo, che si trova nella parte inferiore della pagina, ha un titolo ma nessun bordo.

Commenti

Il IndexOf metodo è utile se sono presenti più EditorPart controlli in una pagina Web part ed è necessario individuare un determinato controllo nella raccolta.

Si applica a

Vedi anche