MenuItemBindingCollection 类
定义
表示 MenuItemBinding 对象集合。Represents a collection of MenuItemBinding objects.
public ref class MenuItemBindingCollection sealed : System::Web::UI::StateManagedCollection
public sealed class MenuItemBindingCollection : System.Web.UI.StateManagedCollection
type MenuItemBindingCollection = class
inherit StateManagedCollection
Public NotInheritable Class MenuItemBindingCollection
Inherits StateManagedCollection
- 继承
示例
下面的代码示例演示如何以声明方式填充 MenuItemBindingCollection 对象。The following code example demonstrates how to populate a MenuItemBindingCollection object declaratively. 要使此示例正常工作,必须将下面的示例 XML 数据复制到名为 Map.xml 的文件中。For this example to work correctly, you must copy the sample XML data below to a file named Map.xml.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu DataBindings Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu DataBindings Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
datasourceid="MenuSource"
runat="server">
<DataBindings>
<asp:menuitembinding datamember="MapHomeNode"
depth="0"
textfield="title"
navigateurlfield="url"/>
<asp:menuitembinding datamember="MapNode"
depth="1"
textfield="title"
navigateurlfield="url"/>
<asp:menuitembinding datamember="MapNode"
depth="2"
textfield="title"
navigateurlfield="url"/>
</DataBindings>
</asp:menu>
<asp:XmlDataSource id="MenuSource"
datafile="Map.xml"
runat="server"/>
</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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu DataBindings Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu DataBindings Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
datasourceid="MenuSource"
runat="server">
<DataBindings>
<asp:menuitembinding datamember="MapHomeNode"
depth="0"
textfield="title"
navigateurlfield="url"/>
<asp:menuitembinding datamember="MapNode"
depth="1"
textfield="title"
navigateurlfield="url"/>
<asp:menuitembinding datamember="MapNode"
depth="2"
textfield="title"
navigateurlfield="url"/>
</DataBindings>
</asp:menu>
<asp:XmlDataSource id="MenuSource"
datafile="Map.xml"
runat="server"/>
</form>
</body>
</html>
下面的代码示例演示如何以 MenuItemBinding 编程方式将对象添加到 MenuItemBindingCollection 对象。The following code example demonstrates how to add MenuItemBinding objects to a MenuItemBindingCollection object programmatically. 要使此示例正常工作,必须将下面的示例 XML 数据复制到名为 Map.xml 的文件中。For this example to work correctly, you must copy the sample XML data below to a file named Map.xml.
<%@ 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">
void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack)
{
// Create the menu item bindings for the Menu control.
MenuItemBinding binding;
binding = CreateMenuItemBinding("MapHomeNode", 0, "title", "url");
NavigationMenu.DataBindings.Add(binding);
binding = CreateMenuItemBinding("MapNode", 1, "title", "url");
NavigationMenu.DataBindings.Add(binding);
binding = CreateMenuItemBinding("MapNode", 2, "title", "url");
NavigationMenu.DataBindings.Add(binding);
}
}
// This is a helper method to create a MenuItemBinding
// object from the specified parameters.
MenuItemBinding CreateMenuItemBinding(String dataMember, int depth, String textField, String navigateUrlField)
{
// Create a new MenuItemBinding object.
MenuItemBinding binding = new MenuItemBinding();
// Set the properties of the MenuItemBinding object.
binding.DataMember = dataMember;
binding.Depth = depth;
binding.TextField = textField;
binding.NavigateUrlField = navigateUrlField;
return binding;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBindingCollection Add Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBindingCollection Add Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
datasourceid="MenuSource"
runat="server">
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="Map.xml"
runat="server"/>
</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">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Create the menu item bindings for the Menu control.
Dim binding As MenuItemBinding
binding = CreateMenuItemBinding("MapHomeNode", 0, "title", "url")
NavigationMenu.DataBindings.Add(binding)
binding = CreateMenuItemBinding("MapNode", 1, "title", "url")
NavigationMenu.DataBindings.Add(binding)
binding = CreateMenuItemBinding("MapNode", 2, "title", "url")
NavigationMenu.DataBindings.Add(binding)
End If
End Sub
' This is a helper method to create a MenuItemBinding
' object from the specified parameters.
Function CreateMenuItemBinding(ByVal dataMember As String, ByVal depth As Integer, ByVal textField As String, ByVal navigateUrlField As String) As MenuItemBinding
' Create a new MenuItemBinding object.
Dim binding As New MenuItemBinding()
' Set the properties of the MenuItemBinding object.
binding.DataMember = dataMember
binding.Depth = depth
binding.TextField = textField
binding.NavigateUrlField = navigateUrlField
Return binding
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBindingCollection Add Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBindingCollection Add Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
datasourceid="MenuSource"
runat="server">
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="Map.xml"
runat="server"/>
</form>
</body>
</html>
下面是前面示例的示例站点地图数据。The following is sample site map data for the previous examples.
<MapHomeNode url="~\Home.aspx"
title="Home"
description="Home">
<MapNode url="~\Music.aspx"
title="Music"
description="Music">
<MapNode url="~\Classical.aspx"
title="Classical"
description="Classical"/>
<MapNode url="~\Rock.aspx"
title="Rock"
description="Rock"/>
<MapNode url="~\Jazz.aspx"
title="Jazz"
description="Jazz"/>
</MapNode>
<MapNode url="~\Movies.aspx"
title="Movies"
description="Movies">
<MapNode url="~\Action.aspx"
title="Action"
description="Action"/>
<MapNode url="~\Drama.aspx"
title="Drama"
description="Drama"/>
<MapNode url="~\Musical.aspx"
title="Musical"
description="Musical"/>
</MapNode>
</MapHomeNode>
注解
MenuItemBindingCollection类用于存储和管理 MenuItemBinding 控件中对象的集合 Menu 。The MenuItemBindingCollection class is used to store and manage a collection of MenuItemBinding objects in the Menu control. Menu控件使用 MenuItemBindingCollection 类作为其属性的数据类型 DataBindings 。The Menu control uses the MenuItemBindingCollection class as the data type for its DataBindings property. DataBindings属性用于存储为控件定义的任何菜单项绑定 Menu 。The DataBindings property is used to store any menu item bindings defined for the Menu control.
备注
MenuItemBinding对象在集合中的显示顺序对这些对象如何应用于控件中的菜单项没有任何影响 Menu 。The order in which MenuItemBinding objects appear in the collection has no effect on how those objects are applied to the menu items in a Menu control.
MenuItemBindingCollection类支持多种方法来访问集合中的项:The MenuItemBindingCollection class supports several ways to access the items in the collection:
使用 Item[] 索引器直接检索特定的 MenuItemBinding 从零开始的索引处的对象。Use the Item[] indexer to directly retrieve the MenuItemBinding object at a specific zero-based index.
使用 GetEnumerator 方法可创建一个可用于循环访问集合的枚举器。Use the GetEnumerator method to create an enumerator that can be used to iterate through the collection.
使用 CopyTo 方法可将集合的内容复制到数组中。Use the CopyTo method to copy the contents of the collection into an array.
可以 MenuItemBindingCollection 通过添加和删除对象以编程方式管理对象 MenuItemBinding 。You can programmatically manage a MenuItemBindingCollection object by adding and removing MenuItemBinding objects. 若要向集合中添加菜单项,请使用 Add 或 Insert 方法。To add menu items to the collection, use the Add or the Insert method. 若要从集合中删除节点,请使用 Remove 、 RemoveAt 或 Clear 方法。To remove nodes from the collection, use the Remove, the RemoveAt, or the Clear method.
MenuItemBindingCollection类包含的属性和方法可用于检索有关集合本身的信息。The MenuItemBindingCollection class contains properties and methods that allow you to retrieve information about the collection itself. 若要确定集合中有多少项,请使用 Count 属性。To find out how many items are in the collection, use the Count property. 如果要确定集合是否包含某个 MenuItemBinding 对象,请使用 Contains 方法。If you want to determine whether the collection contains a certain MenuItemBinding object, use the Contains method. 若要获取 MenuItemBinding 集合中对象的索引,请使用 IndexOf 方法。To get the index of a MenuItemBinding object in the collection, use the IndexOf method.
属性
| Count |
获取 StateManagedCollection 集合中包含的元素的数量。Gets the number of elements contained in the StateManagedCollection collection. (继承自 StateManagedCollection) |
| Item[Int32] |
获取集合中指定索引处的 MenuItemBinding 对象。Gets the MenuItemBinding object at the specified index from the collection. |
方法
| Add(MenuItemBinding) |
将指定的 MenuItemBinding 对象追加到集合末尾。Appends the specified MenuItemBinding object to the end of the collection. |
| Clear() |
从 StateManagedCollection 集合中删除所有项。Removes all items from the StateManagedCollection collection. (继承自 StateManagedCollection) |
| Contains(MenuItemBinding) |
确定指定的 MenuItemBinding 对象是否在集合中。Determines whether the specified MenuItemBinding object is in the collection. |
| CopyTo(Array, Int32) |
从特定的数组索引开始,将 StateManagedCollection 集合的元素复制到数组中。Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index. (继承自 StateManagedCollection) |
| CopyTo(MenuItemBinding[], Int32) |
从目标数组的指定索引开始,将 MenuItemBindingCollection 对象中的所有项复制到 MenuItemBinding 对象的一维兼容数组。Copies all the items from the MenuItemBindingCollection object to a compatible one-dimensional array of MenuItemBinding objects, starting at the specified index in the target array. |
| CreateKnownType(Int32) |
在派生类中替代时,创建实现 IStateManager 的类的实例。When overridden in a derived class, creates an instance of a class that implements IStateManager. 所创建对象的类型基于由 GetKnownTypes() 方法返回的集合的指定成员。The type of object created is based on the specified member of the collection returned by the GetKnownTypes() method. (继承自 StateManagedCollection) |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| GetEnumerator() |
返回循环访问 StateManagedCollection 集合的迭代器。Returns an iterator that iterates through the StateManagedCollection collection. (继承自 StateManagedCollection) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetKnownTypes() |
在派生类中替代时,获取 StateManagedCollection 集合可以包含的 IStateManager 类型的数组。When overridden in a derived class, gets an array of IStateManager types that the StateManagedCollection collection can contain. (继承自 StateManagedCollection) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| IndexOf(MenuItemBinding) |
确定集合中指定 MenuItemBinding 对象的索引。Determines the index of the specified MenuItemBinding object in the collection. |
| Insert(Int32, MenuItemBinding) |
将指定的 MenuItemBinding 对象添加到集合中的指定索引位置。Adds the specified MenuItemBinding object to the collection at the specified index location. |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| OnClear() |
在派生类中替代时,在 Clear() 方法从集合中删除所有项之前执行附加工作。When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection. (继承自 StateManagedCollection) |
| OnClearComplete() |
在派生类中替代时,在 Clear() 方法完成从集合中删除所有项之后执行附加工作。When overridden in a derived class, performs additional work after the Clear() method finishes removing all items from the collection. (继承自 StateManagedCollection) |
| OnInsert(Int32, Object) |
在派生类中替代时,在 IList.Insert(Int32, Object) 或 IList.Add(Object) 方法向集合中添加项之前执行附加工作。When overridden in a derived class, performs additional work before the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection. (继承自 StateManagedCollection) |
| OnInsertComplete(Int32, Object) |
在派生类中替代时,在 IList.Insert(Int32, Object) 或 IList.Add(Object) 方法向集合中添加项之后执行附加工作。When overridden in a derived class, performs additional work after the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection. (继承自 StateManagedCollection) |
| OnRemove(Int32, Object) |
在派生类中替代时,在 IList.Remove(Object) 或 IList.RemoveAt(Int32) 方法从集合中删除指定项之前执行附加工作。When overridden in a derived class, performs additional work before the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection. (继承自 StateManagedCollection) |
| OnRemoveComplete(Int32, Object) |
在派生类中替代时,在 IList.Remove(Object) 或 IList.RemoveAt(Int32) 方法从集合中删除指定项之后执行附加工作。When overridden in a derived class, performs additional work after the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection. (继承自 StateManagedCollection) |
| OnValidate(Object) |
在派生类中替代时,验证 StateManagedCollection 集合的一个元素。When overridden in a derived class, validates an element of the StateManagedCollection collection. (继承自 StateManagedCollection) |
| Remove(MenuItemBinding) |
从集合中移除指定的 MenuItemBinding 对象。Removes the specified MenuItemBinding object from the collection. |
| RemoveAt(Int32) |
从集合中移除位于指定索引位置的 MenuItemBinding 对象。Removes the MenuItemBinding object at the specified index location from the collection. |
| SetDirty() |
强制将整个 StateManagedCollection 集合序列化为视图状态。Forces the entire StateManagedCollection collection to be serialized into view state. (继承自 StateManagedCollection) |
| SetDirtyObject(Object) |
在派生类中替代时,指示集合包含的 |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
显式接口实现
| ICollection.Count |
获取 StateManagedCollection 集合中包含的元素的数量。Gets the number of elements contained in the StateManagedCollection collection. (继承自 StateManagedCollection) |
| ICollection.IsSynchronized |
获取指示 StateManagedCollection 集合是否已同步(线程安全)的值。Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). 此方法在所有情况下均返回 |
| ICollection.SyncRoot |
获取可用于同步对 StateManagedCollection 集合的访问的对象。Gets an object that can be used to synchronize access to the StateManagedCollection collection. 此方法在所有情况下均返回 |
| IEnumerable.GetEnumerator() |
返回循环访问 StateManagedCollection 集合的迭代器。Returns an iterator that iterates through the StateManagedCollection collection. (继承自 StateManagedCollection) |
| IList.Add(Object) |
向 StateManagedCollection 集合中添加一个项。Adds an item to the StateManagedCollection collection. (继承自 StateManagedCollection) |
| IList.Clear() |
从 StateManagedCollection 集合中删除所有项。Removes all items from the StateManagedCollection collection. (继承自 StateManagedCollection) |
| IList.Contains(Object) |
确定 StateManagedCollection 集合中是否包含特定值。Determines whether the StateManagedCollection collection contains a specific value. (继承自 StateManagedCollection) |
| IList.IndexOf(Object) |
确定 StateManagedCollection 集合中的指定项的索引。Determines the index of a specified item in the StateManagedCollection collection. (继承自 StateManagedCollection) |
| IList.Insert(Int32, Object) |
将项在指定索引处插入 StateManagedCollection 集合中。Inserts an item into the StateManagedCollection collection at the specified index. (继承自 StateManagedCollection) |
| IList.IsFixedSize |
获取指示 StateManagedCollection 集合是否具有固定大小的值。Gets a value indicating whether the StateManagedCollection collection has a fixed size. 此方法在所有情况下均返回 |
| IList.IsReadOnly |
获取指示 StateManagedCollection 集合是否为只读的值。Gets a value indicating whether the StateManagedCollection collection is read-only. (继承自 StateManagedCollection) |
| IList.Item[Int32] |
获取指定索引处的 IStateManager 元素。Gets the IStateManager element at the specified index. (继承自 StateManagedCollection) |
| IList.Remove(Object) |
从 StateManagedCollection 集合中删除指定对象的第一个匹配项。Removes the first occurrence of the specified object from the StateManagedCollection collection. (继承自 StateManagedCollection) |
| IList.RemoveAt(Int32) |
删除指定索引处的 IStateManager 元素。Removes the IStateManager element at the specified index. (继承自 StateManagedCollection) |
| IStateManager.IsTrackingViewState |
获取指示 StateManagedCollection 集合是否保存对其视图状态的更改的值。Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state. (继承自 StateManagedCollection) |
| IStateManager.LoadViewState(Object) |
还原 StateManagedCollection 集合以及其包含的 IStateManager 项的以前保存的视图状态。Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains. (继承自 StateManagedCollection) |
| IStateManager.SaveViewState() |
保存自页回发到服务器后对 StateManagedCollection 集合和该集合包含的每个 IStateManager 对象所做的更改。Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server. (继承自 StateManagedCollection) |
| IStateManager.TrackViewState() |
使 StateManagedCollection 集合及其包含的每个 IStateManager 对象跟踪对它们的视图状态所做的更改,以使它们可以在相同页的请求之间得以保持。Causes the StateManagedCollection collection and each of the IStateManager objects it contains to track changes to their view state so they can be persisted across requests for the same page. (继承自 StateManagedCollection) |
扩展方法
| Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type. |
| OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type. |
| AsParallel(IEnumerable) |
启用查询的并行化。Enables parallelization of a query. |
| AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。Converts an IEnumerable to an IQueryable. |