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 の、0 から始まるインデックス番号。

プロパティ値

コレクション内の指定したインデックス位置の 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 できます。

適用対象

こちらもご覧ください