请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
 CatalogDisplayMode 字段

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
WebPartManager.CatalogDisplayMode 字段

注意:此字段在 .NET Framework 2.0 版中是新增的。

表示用于从控件目录向网页添加服务器控件的显示模式。此字段为只读。

命名空间:System.Web.UI.WebControls.WebParts
程序集:System.Web(在 system.web.dll 中)

Visual Basic(声明)
Public Shared ReadOnly CatalogDisplayMode As WebPartDisplayMode
Visual Basic(用法)
Dim value As WebPartDisplayMode

value = WebPartManager.CatalogDisplayMode
C#
public static readonly WebPartDisplayMode CatalogDisplayMode
C++
public:
static initonly WebPartDisplayMode^ CatalogDisplayMode
J#
public static final WebPartDisplayMode CatalogDisplayMode
JScript
public static final var CatalogDisplayMode : WebPartDisplayMode

CatalogDisplayMode 字段引用一个自定义 WebPartDisplayMode 对象,该对象由 WebPartManager 控件创建,并包含在该控件中。因为这是一个静态对象,所以可以通过 WebPartManager 类直接引用它,而无需该控件的实例。

用户要向某页添加控件时,如果服务器控件的目录可用,则可将该页切换至 CatalogDisplayMode(目录模式),此时将显示目录用户界面 (UI)。Web 部件目录的用户界面由 CatalogZoneBase 区域控件提供。开发人员在设计时将此区域添加到页中,然后将服务器控件添加到该区域中,以便用户能够在运行时将这些控件添加到他们的页中。开发人员添加完这些控件后,因为启用目录模式所需的控件都已齐备,所以目录模式成为页上受支持的显示模式。

用户将某页切换到目录模式时,已添加到该页中的区域及所有服务器控件都会变得可见,用户可以从目录选择控件添加到页中,或者从页中移除控件。将控件添加到页中之后,将以正常浏览模式显示这些控件并更新页。

下面的代码示例演示如何以编程方式使用 CatalogDisplayMode 字段。代码使用受页支持的显示模式(在此示例中是浏览、设计和目录模式)填充一个下拉列表。由于网页中的 <asp:CatalogZone> 元素及其子元素,目录模式可用。注意,在 Page_PreRender 方法中,代码会检查当前 DisplayMode 属性是否设置为 CatalogDisplayMode。如果是,则 Label1 将可见;否则 Label1 将隐藏。

Visual Basic
<%@ Page Language="VB" %>

<script runat="server">

  Protected Sub Page_Init(ByVal sender As Object, _
    ByVal e As EventArgs)
    Dim mode As WebPartDisplayMode
    For Each mode In mgr.SupportedDisplayModes
      Dim modeName As String = mode.Name
      If mode.IsEnabled(mgr) Then
        Dim item As ListItem = New ListItem(modeName, modeName)
        DisplayModeDropdown.Items.Add(item)
      End If
    Next
    
  End Sub

  Protected Sub DisplayModeDropdown_SelectedIndexChanged(ByVal _
    sender As Object, ByVal e As EventArgs)
    Dim selectedMode As String = _
      DisplayModeDropdown.SelectedValue
    Dim mode As WebPartDisplayMode = _
      mgr.SupportedDisplayModes(selectedMode)
    If mode IsNot Nothing Then
      mgr.DisplayMode = mode
    End If
  End Sub
  
  Protected Sub Page_PreRender(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    If mgr.DisplayMode.Equals(WebPartManager.CatalogDisplayMode) Then
      Label1.Visible = True
    Else
      Label1.Visible = False
    End If
  End Sub
</script>

<html  >
<head id="Head1" 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: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:WebPartZone ID="WebPartZone2" runat="server" />
      <asp:CatalogZone ID="CatalogZone1" runat="server">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart 
            ID="DeclarativeCatalogPart1" 
            runat="server">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" />             
            </WebPartsTemplate>
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Catalog Mode" 
        Font-Bold="true"
        Font-Size="125%" />
      <br />
      <asp:DropDownList ID="DisplayModeDropdown" 
        runat="server" 
        AutoPostBack="true"
        Width="120"
        OnSelectedIndexChanged=
        "DisplayModeDropdown_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    </form>
</body>
</html>
C#
<%@ Page Language="C#" %>

<script runat="server">

  protected void Page_Init(object sender, EventArgs e)
  {
    foreach (WebPartDisplayMode mode in mgr.SupportedDisplayModes)
    {
      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.SupportedDisplayModes[selectedMode];
    if (mode != null)
      mgr.DisplayMode = mode;
  }

  protected void Page_PreRender(object sender, EventArgs e)
  {
    if (mgr.DisplayMode == WebPartManager.CatalogDisplayMode)
      Label1.Visible = true;
    else
      Label1.Visible = false;
  }
  
</script>

<html  >
<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: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:WebPartZone ID="WebPartZone2" runat="server" />
      <asp:CatalogZone ID="CatalogZone1" runat="server">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart 
            ID="DeclarativeCatalogPart1" 
            runat="server">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" />             
            </WebPartsTemplate>
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Catalog Mode" 
        Font-Bold="true"
        Font-Size="125%" />
      <br />
      <asp:DropDownList ID="DisplayModeDropdown" 
        runat="server" 
        AutoPostBack="true"
        Width="120"
        OnSelectedIndexChanged=
        "DisplayModeDropdown_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    </form>
</body>
</html>

默认情况下,在浏览器中加载页后会处于浏览模式。注意,页上的标签是隐藏的。使用下拉列表控件将页切换至目录模式。注意,由于 Page_PreRender 方法中的代码,该标签现在可见。可以在目录中选择控件,再将它添加至页上两个区域中的任何一个中。

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker