This documentation is archived and is not being maintained.

WebPartManager.DisplayModes Property

Note: This property is new in the .NET Framework version 2.0.

Gets a read-only collection of all display modes that are associated with a WebPartManager control.

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

public WebPartDisplayModeCollection DisplayModes { get; }
/** @property */
public WebPartDisplayModeCollection get_DisplayModes ()

public function get DisplayModes () : WebPartDisplayModeCollection

Property Value

A WebPartDisplayModeCollection that contains the set of WebPartDisplayMode objects associated with the WebPartManager control.

The DisplayModes property references all associated display modes, in contrast with the SupportedDisplayModes property, which references only the display modes that are available (supported) on the current page.

Two of the provided display modes, browse and design, are always supported on a page. The other three display modes, edit, catalog, and connections, are supported only when a page has the corresponding type of zone necessary for a particular display mode to work. For example, if you page does not contain an EditorZone zone, the edit display mode would appear in the collection referenced by the DisplayModes property, but would not appear in the collection referenced by the SupportedDisplayModes property.

The following code example shows the programmatic use of the DisplayModes property. The code uses this property to populate the list with all the display modes available in the Web Parts control set, even those that are not supported on the current page. In this case, the catalog and connect display modes are not supported, because their corresponding required zones are not on the page.

The other three display modes--browse, design, and edit--are supported on the page. Edit mode is supported because the page contains an EditorZone zone, while browse and design modes are always supported.

After you load the page in a browser, you can use the drop-down list control to switch the page from browse mode to design mode, and then to edit mode. In edit mode, you can click the drop-down verbs menu in the header of one of the server controls, and select Edit to edit the control. Note that if you select Catalog or Connect in the drop-down list, an error page is generated.

<%@ Page Language="C#" %>

<script runat="server">

  protected void Page_Init(object sender, EventArgs e)
  {
    foreach (WebPartDisplayMode mode in mgr.DisplayModes)
    {
      string modeName = mode.Name;
      if (mode.IsEnabled(mgr))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }      
    }
  }

  protected void DisplayModeDropdown_SelectedIndexChanged(object 
    sender, EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;
    WebPartDisplayMode mode = mgr.DisplayModes[selectedMode];
    if (mode != null)
      mgr.DisplayMode = mode;
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr" runat="server">
      </asp:WebPartManager>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart runat="server" 
            ID="Appearance1">
          </asp:AppearanceEditorPart>
          <asp:LayoutEditorPart runat="server" ID="Layout1">
          </asp:LayoutEditorPart>
        </ZoneTemplate>
      </asp:EditorZone>
      <hr />
      <asp:DropDownList ID="DisplayModeDropdown" runat="server" 
        AutoPostBack="true"
        Width="120"
        OnSelectedIndexChanged=
        "DisplayModeDropdown_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    </form>
</body>
</html>

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0
Show: