MenuItemBindingCollection.RemoveAt(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定索引位置的物件從集合中移除 MenuItemBinding 。
public:
void RemoveAt(int index);
public void RemoveAt(int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
參數
- index
- Int32
選單項目綁定的索引位置,就是要移除。
範例
以下程式碼範例示範如何使用此 RemoveAt 方法在特定索引處移除 MenuItemBinding 集合中的物件。 為了讓這個範例正確運作,你必須將下方的範例 XML 資料複製到一個名為 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)
{
// Use the RemoveAt method to remove the
// MenuItemBinding object at index 3 from
// the Bindings collection.
NavigationMenu.DataBindings.RemoveAt(3);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBindingCollection RemoveAt Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBindingCollection RemoveAt Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
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"/>
<asp:menuitembinding datamember="ExtraMapNode"
depth="3"
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">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Use the RemoveAt method to remove the
' MenuItemBinding object at index 3 from
' the Bindings collection.
NavigationMenu.DataBindings.RemoveAt(3)
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBindingCollection RemoveAt Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBindingCollection RemoveAt Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
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"/>
<asp:menuitembinding datamember="ExtraMapNode"
depth="3"
textfield="title"
navigateurlfield="url"/>
</databindings>
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="Map.xml"
runat="server"/>
</form>
</body>
</html>
以下是前一個範例的現場地圖範例資料。
<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>
備註
使用 RemoveAt 該方法將指定索引位置的物件從集合中移除 MenuItemBinding 。 所有緊接該選單項目後的項目都會往上移動,填補空缺位置。 移動項目的索引也會更新。
Note
該集合可以包含空值,也可以包含重複 MenuItemBinding 的物件。
作為替代方案,你也可以使用這個MenuItemBinding方法移除特定Remove物件。 你也可以用這個 Clear 方法把所有菜單項目從收藏中移除。