Bagikan melalui


WebPartDisplayModeCollection.Add(WebPartDisplayMode) Metode

Definisi

WebPartDisplayMode Menambahkan objek ke koleksi.

public:
 int Add(System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ value);
public int Add (System.Web.UI.WebControls.WebParts.WebPartDisplayMode value);
member this.Add : System.Web.UI.WebControls.WebParts.WebPartDisplayMode -> int
Public Function Add (value As WebPartDisplayMode) As Integer

Parameter

value
WebPartDisplayMode

A WebPartDisplayMode untuk ditambahkan ke koleksi.

Mengembalikan

Nilai bilangan bulat yang menunjukkan di mana WebPartDisplayMode dimasukkan ke dalam koleksi.

Contoh

Contoh kode ini menunjukkan penggunaan WebPartDisplayModeCollection kelas . Untuk kode lengkap dan instruksi yang diperlukan untuk menjalankan contoh, lihat bagian Contoh dari WebPartDisplayModeCollection gambaran umum kelas.

Bagian kode berikut terjadi di kelas turunan WebPartManager yang mengambil CreateDisplayModes alih metode dan menambahkan mode tampilan kustom ke koleksi.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
  Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class NewWebPartManager : WebPartManager 
  {
    private static readonly WebPartDisplayMode _inLineEditDisplayMode =
      new InlineWebPartEditDisplayMode();

    public NewWebPartManager() {}

    protected override WebPartDisplayModeCollection CreateDisplayModes() 
    {
      WebPartDisplayModeCollection displayModes = 
        base.CreateDisplayModes();
      displayModes.Add(_inLineEditDisplayMode);
      return displayModes;
    }

    public WebPartDisplayMode InLineEditDisplayMode
    {
      get { return _inLineEditDisplayMode; }
    }

    private sealed class InlineWebPartEditDisplayMode : WebPartDisplayMode
    {
      public InlineWebPartEditDisplayMode()
        : base("Inline Edit Display")
      {
      }
      public override bool AllowPageDesign
      {
        get { return true; }
      }
      public override bool RequiresPersonalization
      {
        get { return true; }
      }
      public override bool ShowHiddenWebParts
      {
        get { return false; }
      }
      public override bool AssociatedWithToolZone
      {
        get { return false; }
      }
      public override bool IsEnabled(WebPartManager webPartManager)
      {
        return true;
      }
    }
  }
}
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Security.Permissions
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class NewWebPartManager
    Inherits WebPartManager
    Private Shared _inLineEditDisplayMode As WebPartDisplayMode = _
      New InlineWebPartEditDisplayMode()

    Public Sub New()
    End Sub

    Protected Overrides Function CreateDisplayModes() As WebPartDisplayModeCollection
      Dim displayModes As WebPartDisplayModeCollection = MyBase.CreateDisplayModes()
      displayModes.Add(_inLineEditDisplayMode)
      Return displayModes

    End Function 

    Public ReadOnly Property InLineEditDisplayMode() As WebPartDisplayMode
        Get
            Return _inLineEditDisplayMode
        End Get
    End Property

    Private NotInheritable Class InlineWebPartEditDisplayMode
      Inherits WebPartDisplayMode

      Public Sub New()
        MyBase.New("Inline Edit Display")
      End Sub

      Public Overrides ReadOnly Property AllowPageDesign() As Boolean
        Get
          Return True
        End Get
      End Property

      Public Overrides ReadOnly Property RequiresPersonalization() _
        As Boolean
        Get
          Return True
        End Get
      End Property

      Public Overrides ReadOnly Property ShowHiddenWebParts() As Boolean
        Get
          Return False
        End Get
      End Property

      Public Overrides ReadOnly Property AssociatedWithToolZone() _
        As Boolean
        Get
          Return False
        End Get
      End Property

      Public Overrides Function IsEnabled(ByVal webPartManager _
        As WebPartManager) As Boolean

        Return True

      End Function

    End Class

  End Class

End Namespace

Keterangan

Anda dapat menggunakan Add metode untuk menambahkan objek baru WebPartDisplayMode ke objek yang sudah ada WebPartDisplayModeCollection .

Contoh skenario di mana Anda akan melakukan ini adalah ketika Anda membuat kelas kustom WebPartDisplayMode , dan Anda ingin menambahkannya ke koleksi mode tampilan yang didukung di halaman. Untuk melakukannya, Anda harus mewarisi dari WebPartManager kelas dan mengambil alih metodenya CreateDisplayModes , pertama-tama memanggil metode dasar, lalu menggunakan Add metode untuk menambahkan mode tampilan kustom ke koleksi.

Berlaku untuk

Lihat juga