Share via


MenuItemBinding.Depth 屬性

定義

取得或設定套用 MenuItemBinding 物件的功能表深度。

public:
 property int Depth { int get(); void set(int value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public int Depth { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Depth : int with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.TreeNodeBindingDepthConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Depth : int with get, set
Public Property Depth As Integer

屬性值

要套用 MenuItemBinding 的功能表深度。 預設值為 -1,表示這個屬性未設定。

屬性

範例

下列程式碼範例示範如何使用 Depth 屬性來指定套用 MenuItemBinding 物件的功能表深度。 若要讓此範例正常運作,您必須將下面的範例 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Depth Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Depth Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <databindings>
        
          <asp:menuitembinding depth="0"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding depth="2"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </databindings>
        
      </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Depth Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Depth Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <databindings>
        
          <asp:menuitembinding depth="0"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding depth="2"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </databindings>
        
      </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 物件時,您必須指定系結的準則。 準則會指出資料項目何時應該系結至功能表項目。 您可以指定 Depth 屬性、 DataMember 屬性或兩者。

Depth使用 屬性來指定要套用 MenuItemBinding 物件的功能表深度。 例如,下列 MenuItemBinding 宣告會將資料來源的 Name 和 ID 欄位分別系結至 TextValue 屬性,以及深度為 0 的所有功能表項目:

<asp:MenuItemBinding Depth="0" TextField="Name" ValueField="ID">  

有時候您可能需要建立功能表項目系結,以指定深度和資料成員。 當資料來源包含具有相同資料成員值的不同層級的專案時,通常會使用這個值。 例如,您可以有 <Item> 出現在 XML 檔案內不同層級的專案。 下列 MenuItemBinding 宣告示範如何指定套用至不同功能表深度相同資料成員的功能表項目系結:

<asp:MenuItemBinding DataMember="Item" Depth="1" TextField="Title">

<asp:MenuItemBinding DataMember="Item" Depth="2" TextField="ISBN">

如果定義功能表項目系結時沒有深度和資料成員,功能表項目系結就會套用至功能表內的所有功能表項目。 當所有資料項目都具有相同的屬性,而且不論功能表深度為何,都應該以相同方式顯示時,通常會使用此方式。

建立系結準則之後,您就可以系結可系結至值之 MenuItem 物件的屬性。 您可以系結至資料項目的欄位或靜態值。 系結至靜態值時,套用物件的所有 MenuItem 物件 MenuItemBinding 都會共用相同的值。 系結至欄位的屬性包含資料來源中欄位的值。

如果定義衝突 MenuItemBinding 的物件,控制項 Menu 會以下列優先順序套用功能表項目系結:

  1. 定義 MenuItemBinding 及比對深度和資料成員的物件。

  2. MenuItemBinding 定義並符合資料成員的物件。

  3. MenuItemBinding 定義並符合深度的物件。

  4. 定義 MenuItemBinding 深度或資料成員的物件。 (此類型的功能表項目系結會套用至 menu 中的所有功能表項目。)

  5. 資料來源 MenuItemBinding 中沒有相符專案的物件。 在此情況下,資料項目方法所 ToString() 傳回的值會接著系結至 Text 套用物件的功能表項目 MenuItemBindingValue 屬性。

適用於

另請參閱