MenuItemBindingCollection.Insert(Int32, MenuItemBinding) Methode

Definition

Fügt der Auflistung das angegebene MenuItemBinding-Objekt an der angegebenen Indexposition hinzu.Adds the specified MenuItemBinding object to the collection at the specified index location.

public:
 void Insert(int index, System::Web::UI::WebControls::MenuItemBinding ^ binding);
public void Insert (int index, System.Web.UI.WebControls.MenuItemBinding binding);
member this.Insert : int * System.Web.UI.WebControls.MenuItemBinding -> unit
Public Sub Insert (index As Integer, binding As MenuItemBinding)

Parameter

index
Int32

Der Speicherort des nullbasierten Index, an dem MenuItemBinding eingefügt werden soll.The zero-based index location at which to insert the MenuItemBinding.

binding
MenuItemBinding

Der einzufügende MenuItemBinding.The MenuItemBinding to insert.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die Insert -Methode verwendet wird MenuItemBinding , um der Auflistung ein-Objekt an einem bestimmten Index hinzuzufügen.The following code example demonstrates how to use the Insert method to add a MenuItemBinding object to the collection at a specific index. Damit dieses Beispiel ordnungsgemäß funktioniert, müssen Sie die folgenden XML-Beispiel Daten in eine Datei mit dem Namen "map. xml" kopieren.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 MenuItemBinding object to insert.
      MenuItemBinding binding;      
      binding = CreateMenuItemBinding("MapNode", 1, "title", "url");

      // Use the Insert method to add the MenuItemBinding 
      // object to the Bindings collection at index 1.
      NavigationMenu.DataBindings.Insert(1, 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 Insert Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemBindingCollection Insert 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="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">
<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
 
    If Not IsPostBack Then
    
      ' Create the MenuItemBinding object to insert.
      Dim binding As MenuItemBinding      
      binding = CreateMenuItemBinding("MapNode", 1, "title", "url")

      ' Use the Insert method to add the MenuItemBinding 
      ' object to the Bindings collection at index 1.
      NavigationMenu.DataBindings.Insert(1, 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 Insert Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemBindingCollection Insert 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="2"
            textfield="title" 
            navigateurlfield="url"/>
        </DataBindings>
                
      </asp:menu>
      
      <asp:xmldatasource id="MenuSource"
        datafile="Map.xml"
        runat="server"/>        

    </form>
  </body>
</html>

Im folgenden finden Sie Beispiele für Site Übersichts Daten für das vorherige Beispiel.The following is sample site map data for the previous example.

<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>

Hinweise

Verwenden Sie Insert die-Methode, um MenuItemBinding das angegebene Objekt am angegebenen Index in die Auflistung einzufügen.Use the Insert method to insert the specified MenuItemBinding object in the collection at the specified index.

Hinweis

Sie können der Auflistung NULL-Werte MenuItemBinding und doppelte Objekte hinzufügen.You can add null values and duplicate MenuItemBinding objects to the collection.

Als Alternative können Sie einfach ein MenuItemBinding -Objekt an das Ende der Auflistung anfügen, indem Sie die Add -Methode verwenden.As an alternative, you can simply append a MenuItemBinding object to the end of the collection by using the Add method.

Hinweis

Die Reihenfolge, MenuItemBinding in der Objekte in der Auflistung angezeigt werden, wirkt sich nicht darauf aus, wie diese Objekte auf die Menü Menu Elemente in einem-Steuerelement angewendet werden.The order in which MenuItemBinding objects appear in the collection has no effect on the how those objects are applied to the menu items in a Menu control.

Gilt für:

Siehe auch