MenuItemBinding コンストラクター

定義

MenuItemBinding クラスの新しいインスタンスを初期化します。

public:
 MenuItemBinding();
public MenuItemBinding ();
Public Sub New ()

次のコード例では、このコンストラクターを使用して、コントロールのコレクションを動的に設定する DataBindings 方法を Menu 示します。 この例を正しく機能させるには、以下のサンプル XML データを MenuDepth.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 a new MenuItemBinding object.
      MenuItemBinding binding = new MenuItemBinding();

      // Set the MenuItemBinding object's properties.
      binding.TextField = "Title";
      binding.ValueField = "Description";
      binding.ImageUrlField = "ImageUrl";
      binding.ToolTipField = "ToolTip";

      // Add the MenuItemBinding object to the 
      // DataBindings collection of the Menu control.
      NavigationMenu.DataBindings.Add(binding);
    }
  }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Constructor Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="MenuDepth.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 a new MenuItemBinding object.
      Dim binding As New MenuItemBinding()

      ' Set the MenuItemBinding object's properties.
      binding.TextField = "Title"
      binding.ValueField = "Description"
      binding.ImageUrlField = "ImageUrl"
      binding.ToolTipField = "ToolTip"

      ' Add the MenuItemBinding object to the 
      ' DataBindings collection of the Menu control.
      NavigationMenu.DataBindings.Add(binding)
    
    End If
      
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Constructor Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="MenuDepth.xml"
        runat="server"/> 

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

次のコードは、前の例のサンプル サイト マップ データです。

<MapNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapNode>

注釈

このコンストラクターを使用して、 クラスの新しいインスタンスを MenuItemBinding 作成します。 これは、コントロールのMenuコレクションをDataBindings動的に設定するときによく使用されます。

適用対象

こちらもご覧ください