Compartilhar via


MenuItemBindingCollection.Item[Int32] Propriedade

Definição

Obtém o objeto MenuItemBinding no índice especificado da coleção.

public:
 property System::Web::UI::WebControls::MenuItemBinding ^ default[int] { System::Web::UI::WebControls::MenuItemBinding ^ get(int i); void set(int i, System::Web::UI::WebControls::MenuItemBinding ^ value); };
public System.Web.UI.WebControls.MenuItemBinding this[int i] { get; set; }
member this.Item(int) : System.Web.UI.WebControls.MenuItemBinding with get, set
Default Public Property Item(i As Integer) As MenuItemBinding

Parâmetros

i
Int32

O índice de base zero do MenuItemBinding a recuperar.

Valor da propriedade

MenuItemBinding

O MenuItemBinding índice especificado na coleção.

Exemplos

O exemplo de código a seguir demonstra como recuperar um MenuItemBinding objeto da coleção usando o indexador. As propriedades do MenuItemBinding objeto são atualizadas programaticamente. Para que este exemplo funcione corretamente, você deve copiar os dados XML de exemplo abaixo para um arquivo chamado 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 indexer to retrieve the MenuItemBinding
      // object at index 0.
      MenuItemBinding binding = NavigationMenu.DataBindings[0];

      // Instead of binding the Text property of the Home
      // menu item to a field from a data source, bind it
      // to static text.
      binding.TextField = "";
      binding.Text = "Custom Menu Text";
    }
  }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBindingCollection Indexer Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemBindingCollection Indexer 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"/>
        </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 indexer to retrieve the MenuItemBinding
      ' object at index 0.
      Dim binding As MenuItemBinding = NavigationMenu.DataBindings(0)

      ' Instead of binding the Text property of the Home
      ' menu item to a field from a data source, bind it
      ' to static text.
      binding.TextField = ""
      binding.Text = "Custom Menu Text"
    
    End If
      
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBindingCollection Indexer Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemBindingCollection Indexer 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"/>
        </DataBindings>
                
      </asp:menu>
      
      <asp:xmldatasource id="MenuSource"
        datafile="Map.xml"
        runat="server"/>        

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

Veja a seguir dados de mapa de site de exemplo para o exemplo anterior.

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

Comentários

Use esse indexador para acessar um MenuItemBinding objeto da coleção no índice especificado usando notação de matriz. O indexador permite que você acesse, modifique ou substitua um MenuItemBinding objeto diretamente na coleção.

Aplica-se a

Confira também