WebPartManager.SupportedDisplayModes 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得特定網頁上所有可用顯示模式的唯讀集合。
public:
property System::Web::UI::WebControls::WebParts::WebPartDisplayModeCollection ^ SupportedDisplayModes { System::Web::UI::WebControls::WebParts::WebPartDisplayModeCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.WebControls.WebParts.WebPartDisplayModeCollection SupportedDisplayModes { get; }
[<System.ComponentModel.Browsable(false)>]
member this.SupportedDisplayModes : System.Web.UI.WebControls.WebParts.WebPartDisplayModeCollection
Public ReadOnly Property SupportedDisplayModes As WebPartDisplayModeCollection
屬性值
WebPartDisplayModeCollection,包含特定網頁上可用的 WebPartDisplayMode 物件集合。
- 屬性
範例
下列程式碼範例顯示 屬性的程式 SupportedDisplayModes 設計用法。 程式碼會使用這個屬性來填入清單,只填入目前網頁中可用的顯示模式。
此頁面有三種支援的顯示模式:流覽、設計和編輯。 前兩個一律可供使用,而且此程式碼範例中提供編輯模式,因為頁面包含 EditorZone 控制項。 目錄和連線顯示模式不會顯示,因為它們的對應區域不在此頁面上。
<%@ Page Language="C#" %>
<!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 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;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</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>
<%@ Page Language="VB" %>
<!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 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
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</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>
在瀏覽器中載入頁面之後,您可以使用下拉式清單控制項,將頁面從瀏覽模式切換為設計模式,然後切換至編輯模式。 在編輯模式中,您可以按一下其中一個伺服器控制項標頭中的下拉式動詞功能表,然後選取 [ 編輯 ] 以編輯控制項。
備註
屬性 SupportedDisplayModes 只包含頁面上實際可用的顯示模式,前提是頁面上存在的區域控制項類型。
注意
可以停用顯示模式,而且當顯示模式停用時,它不會新增至 SupportedDisplayModes 集合,即使支援該顯示模式的對應區欄位型別也會出現在頁面上。
一律支援瀏覽模式和設計模式。 可能會有所不同的顯示模式是編輯、目錄和連接模式。 這些顯示模式都與特定類型的 ToolZone 控制項相關聯。 這是網頁上有該特殊類型的區域,導致特定顯示模式加入屬性所參考的 SupportedDisplayModes 集合。 例如,如果網頁包含 EditorZone 區域,但不包含 CatalogZone 區域,則編輯顯示模式是該頁面上支援的模式之一,但不支援目錄顯示模式。
注意
屬性與 DisplayModes 屬性不同,該 SupportedDisplayModes 屬性會參考集合,其中包含目前 WebPartManager 控制項可用的所有顯示模式,甚至是特定頁面上不支援的顯示模式。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應