Bagikan melalui


EditorPartCollection.IndexOf(EditorPart) Metode

Definisi

Mengembalikan posisi anggota koleksi tertentu.

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

Parameter

editorPart
EditorPart

Yang EditorPart merupakan anggota koleksi.

Mengembalikan

Bilangan bulat yang sesuai dengan indeks EditorPart kontrol dalam koleksi.

Contoh

Contoh kode berikut menunjukkan cara menggunakan IndexOf metode untuk menemukan EditorPart kontrol dalam EditorPartCollection objek. Untuk kode lengkap yang diperlukan untuk menjalankan contoh, lihat bagian Contoh dari EditorPartCollection gambaran umum kelas.

Kode dalam Button1_Click peristiwa membuat EditorPartCollection objek, lalu menggunakan IndexOf metode untuk menemukan PropertyGridEditorPart1 kontrol dalam koleksi, dan mengatur propertinya ChromeType .

<!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>

Saat memuat halaman di browser, Anda dapat mengalihkan halaman ke mode edit dengan memilih Edit di kontrol daftar drop-down Mode Tampilan . Anda dapat mengklik menu kata kerja (panah ke bawah) di bilah TextDisplayWebPart judul kontrol, dan klik Edit untuk mengedit kontrol. Saat antarmuka pengguna pengeditan (UI) terlihat, Anda dapat melihat semua EditorPart kontrol. Jika Anda mengklik tombol Buat EditorPartCollection , Anda akan melihat bahwa PropertyGridEditorPart1 kontrol, yang berada di dekat bagian bawah halaman, memiliki judul tetapi tidak ada batas.

Keterangan

Metode IndexOf ini berguna jika Anda memiliki beberapa EditorPart kontrol pada halaman Bagian Web, dan Anda perlu menemukan kontrol tertentu dalam koleksi.

Berlaku untuk

Lihat juga