MenuItemBindingCollection.Item[Int32] 属性

定义

获取集合中指定索引处的 MenuItemBinding 对象。

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

参数

i
Int32

要检索的 MenuItemBinding 的从零开始的索引。

属性值

MenuItemBinding

位于集合中指定索引处的 MenuItemBinding

示例

下面的代码示例演示如何使用索引器从集合中检索 MenuItemBinding 对象。 然后,以编程方式更新对象的属性 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 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>

下面是上一示例的示例站点地图数据。

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

注解

使用此索引器可以使用 MenuItemBinding 数组表示法从集合访问集合中的对象。 索引器允许直接访问、修改或替换 MenuItemBinding 集合中的对象。

适用于

另请参阅