MenuItemBindingCollection.RemoveAt(Int32) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
MenuItemBinding Usuwa obiekt w określonej lokalizacji indeksu z kolekcji.
public:
void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)
Parametry
- index
- Int32
Lokalizacja indeksu zerowego powiązania elementu menu do usunięcia.
Przykłady
W poniższym przykładzie kodu pokazano, jak za pomocą RemoveAt metody usunąć MenuItemBinding obiekt z kolekcji w określonym indeksie. Aby ten przykład działał poprawnie, należy skopiować przykładowe dane XML poniżej do pliku o nazwie 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>
Poniżej przedstawiono przykładowe dane mapy witryny dla poprzedniego przykładu.
<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>
Uwagi
RemoveAt Użyj metody , aby usunąć MenuItemBinding obiekt w określonej lokalizacji indeksu z kolekcji. Wszystkie elementy, które następują po tym elemencie menu, są następnie przenoszone w górę, aby wypełnić wolne położenie. Indeksy przeniesionych elementów również są aktualizowane.
Uwaga
Kolekcja może zawierać wartości null, a także zduplikowane MenuItemBinding obiekty.
Alternatywnie można usunąć określony MenuItemBinding obiekt przy użyciu Remove metody . Możesz również usunąć wszystkie elementy menu z kolekcji przy użyciu Clear metody .