SiteMapNodeItem(Int32, SiteMapNodeItemType) Konstruktor

Definition

Initialisiert eine neue Instanz der SiteMapNodeItem-Klasse mit dem angegebenen Index und SiteMapNodeItemType.Initializes a new instance of the SiteMapNodeItem class, using the specified index and SiteMapNodeItemType.

public:
 SiteMapNodeItem(int itemIndex, System::Web::UI::WebControls::SiteMapNodeItemType itemType);
public SiteMapNodeItem (int itemIndex, System.Web.UI.WebControls.SiteMapNodeItemType itemType);
new System.Web.UI.WebControls.SiteMapNodeItem : int * System.Web.UI.WebControls.SiteMapNodeItemType -> System.Web.UI.WebControls.SiteMapNodeItem
Public Sub New (itemIndex As Integer, itemType As SiteMapNodeItemType)

Parameter

itemIndex
Int32

Der Index in der Controls-Auflistung, den das SiteMapPath-Steuerelement zum Verfolgen des SiteMapNodeItem-Objekts verwendet.The index in the Controls collection that the SiteMapPath control uses to track the SiteMapNodeItem object.

itemType
SiteMapNodeItemType

Der funktionale Typ des SiteMapNode, den dieses SiteMapNodeItem darstellt.The functional type of SiteMapNode that this SiteMapNodeItem represents.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie ein SiteMapNodeItem -Objekt erstellt wird.The following code example demonstrates how to create a SiteMapNodeItem object. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die SiteMapPath -Klasse bereitgestellt wird.This code example is part of a larger example provided for the SiteMapPath class.

private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item) {

    SiteMapNodeCollection childNodes = item.SiteMapNode.ChildNodes;

    // Only do this work if there are child nodes.
    if (childNodes != null) {

        // Add another PathSeparator after the CurrentNode.
        SiteMapNodeItem finalSeparator =
            new SiteMapNodeItem(item.ItemIndex,
                                SiteMapNodeItemType.PathSeparator);

        SiteMapNodeItemEventArgs eventArgs =
            new SiteMapNodeItemEventArgs(finalSeparator);

        InitializeItem(finalSeparator);
        // Call OnItemCreated every time a SiteMapNodeItem is
        // created and initialized.
        OnItemCreated(eventArgs);

        // The pathSeparator does not bind to any SiteMapNode, so
        // do not call DataBind on the SiteMapNodeItem.
        item.Controls.Add(finalSeparator);

        // Create a DropDownList and populate it with the children of the
        // CurrentNode. There are no styles or templates that are applied
        // to the DropDownList control. If OnSelectedIndexChanged is raised,
        // the event handler redirects to the page selected.
        // The CurrentNode has child nodes.
        DropDownList ddList = new DropDownList();
        ddList.AutoPostBack = true;

        ddList.SelectedIndexChanged += new EventHandler(this.DropDownNavPathEventHandler);

        // Add a ListItem to the DropDownList for every node in the
        // SiteMapNodes collection.
        foreach (SiteMapNode node in childNodes) {
            ddList.Items.Add(new ListItem(node.Title, node.Url));
        }

        item.Controls.Add(ddList);
    }
}
Private Sub AddDropDownListAfterCurrentNode(item As SiteMapNodeItem)

   Dim childNodes As SiteMapNodeCollection = item.SiteMapNode.ChildNodes

   ' Only do this work if there are child nodes.
   If Not (childNodes Is Nothing) Then

      ' Add another PathSeparator after the CurrentNode.
      Dim finalSeparator As New SiteMapNodeItem(item.ItemIndex, SiteMapNodeItemType.PathSeparator)

      Dim eventArgs As New SiteMapNodeItemEventArgs(finalSeparator)

      InitializeItem(finalSeparator)
      ' Call OnItemCreated every time a SiteMapNodeItem is
      ' created and initialized.
      OnItemCreated(eventArgs)

      ' The pathSeparator does not bind to any SiteMapNode, so
      ' do not call DataBind on the SiteMapNodeItem.
      item.Controls.Add(finalSeparator)

      ' Create a DropDownList and populate it with the children of the
      ' CurrentNode. There are no styles or templates that are applied
      ' to the DropDownList control. If OnSelectedIndexChanged is raised,
      ' the event handler redirects to the page selected.
      ' The CurrentNode has child nodes.
      Dim ddList As New DropDownList()
      ddList.AutoPostBack = True

      AddHandler ddList.SelectedIndexChanged, AddressOf Me.DropDownNavPathEventHandler

      ' Add a ListItem to the DropDownList for every node in the
      ' SiteMapNodes collection.
      Dim node As SiteMapNode
      For Each node In  childNodes
         ddList.Items.Add(New ListItem(node.Title, node.Url))
      Next node

      item.Controls.Add(ddList)
   End If
End Sub

Hinweise

Wenn den PathDirection RootToCurrentWert hat, können Sie alle tieferen Elemente der Standort Navigations Hierarchie Controls am Ende der Sammlung hinzufügen.If the PathDirection is RootToCurrent, you can add each deeper-level item of the site navigation hierarchy at the end of the Controls collection. Wenn die PathDirection -Eigenschaft jedoch auf CurrentToRootfestgelegt ist, muss jeder Controls übergeordnete Knoten am Anfang der Auflistung eingefügt werden.However, if the PathDirection property is set to CurrentToRoot, each deeper-level node must be inserted at the beginning of the Controls collection.

Gilt für:

Siehe auch