Export (0) Print
Expand All

WebPartDisplayModeCollection.Add Method

Adds a WebPartDisplayMode object to the collection.

Namespace:  System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

public int Add(
	WebPartDisplayMode value
)

Parameters

value
Type: System.Web.UI.WebControls.WebParts.WebPartDisplayMode
A WebPartDisplayMode to add to the collection.

Return Value

Type: System.Int32
An integer value that indicates where the WebPartDisplayMode was inserted into the collection.

You can use the Add method to add new WebPartDisplayMode objects to an existing WebPartDisplayModeCollection object.

An example of a scenario in which you would do this is when you create a custom WebPartDisplayMode class, and you want to add it to the collection of supported display modes on a page. To do that, you must inherit from the WebPartManager class and override its CreateDisplayModes method, first calling the base method, and then using the Add method to add the custom display mode to the collection.

This code example demonstrates the use of the WebPartDisplayModeCollection class. For the full code and instructions required to run the example, see the Example section of the WebPartDisplayModeCollection class overview.

The following section of code occurs in a derived WebPartManager class that overrides the CreateDisplayModes method and adds a custom display mode to the collection.


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;
      }
    }

  }

}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft