WebPartDisplayModeCollection.Add(WebPartDisplayMode) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 WebPartDisplayMode 对象添加到集合中。
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
参数
- value
- WebPartDisplayMode
要添加到集合中的 WebPartDisplayMode。
返回
一个整数值,指示 WebPartDisplayMode 插入到集合中的位置。
示例
此代码示例演示如何使用 WebPartDisplayModeCollection 类。 有关运行示例所需的完整代码和说明,请参阅类概述的 WebPartDisplayModeCollection “示例”部分。
以下代码部分出现在重写 方法并将自定义显示模式添加到集合的派生 WebPartManager 类 CreateDisplayModes 中。
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
注解
可以使用 Add 方法将新 WebPartDisplayMode 对象添加到现有 WebPartDisplayModeCollection 对象。
执行此操作的场景的一个示例是,当你创建自定义 WebPartDisplayMode 类,并且你想要将其添加到页面上支持的显示模式的集合时。 为此,必须从 WebPartManager 类继承并重写其 CreateDisplayModes 方法,首先调用基方法,然后使用 Add 方法将自定义显示模式添加到集合。