SiteMapPath.OnItemCreated(SiteMapNodeItemEventArgs) Method

Definition

Löst das ItemCreated-Ereignis des SiteMapPath-Steuerelements aus.Raises the ItemCreated event of the SiteMapPath control.

protected:
 virtual void OnItemCreated(System::Web::UI::WebControls::SiteMapNodeItemEventArgs ^ e);
protected virtual void OnItemCreated (System.Web.UI.WebControls.SiteMapNodeItemEventArgs e);
abstract member OnItemCreated : System.Web.UI.WebControls.SiteMapNodeItemEventArgs -> unit
override this.OnItemCreated : System.Web.UI.WebControls.SiteMapNodeItemEventArgs -> unit
Protected Overridable Sub OnItemCreated (e As SiteMapNodeItemEventArgs)

Parameters

e
SiteMapNodeItemEventArgs

Ein SiteMapNodeItemEventArgs, das Ereignisdaten enthält.A SiteMapNodeItemEventArgs that contains event data.

Examples

Im folgenden Codebeispiel wird veranschaulicht, wie die OnItemCreated-Methode aufgerufen wird, nachdem ein SiteMapNodeItem innerhalb der InitializeItem-Methode erstellt wurde.The following code example demonstrates how to call the OnItemCreated method after creating a SiteMapNodeItem within the InitializeItem method. 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

Remarks

Das ItemCreated-Ereignis wird ausgelöst, nachdem das SiteMapPath-Steuerelement eine SiteMapNodeItemerstellt hat. Hierbei handelt es sich um ein Webserver Steuerelement, das eine SiteMapNodedarstellt und es einer SiteMapNodezuordnet.The ItemCreated event is raised after the SiteMapPath control creates a SiteMapNodeItem, which is a Web server control that represents a SiteMapNode, and associates it to a SiteMapNode. Die OnItemCreated-Methode wird aufgerufen, bevor das erstellte Knoten Element an seine Daten gebunden wird.The OnItemCreated method is called before the created node item is bound to its data. Dies ermöglicht es Ihnen, eine Ereignis Behandlungsmethode bereitzustellen, die immer dann eine benutzerdefinierte Routine ausführt, wenn ein SiteMapNodeItem erstellt wird.This allows you to provide an event-handling method that performs a custom routine whenever a SiteMapNodeItem is created.

Durch das Auslösen eines Ereignisses wird der Ereignishandler über einen Delegaten aufgerufen.Raising an event invokes the event handler through a delegate. Weitere Informationen finden Sie unter Behandeln und Auslösen von Ereignissen.For more information, see Handling and Raising Events.

Mit der OnItemCreated-Methode können auch abgeleitete Klassen das Ereignis ohne Anfügen eines Delegaten behandeln.The OnItemCreated method also allows derived classes to handle the event without attaching a delegate. Dies ist das bevorzugte Verfahren für die Behandlung des Ereignisses in einer abgeleiteten Klasse.This is the preferred technique for handling the event in a derived class.

Notes to Inheritors

Wenn Sie OnItemCreated(SiteMapNodeItemEventArgs) in einer abgeleiteten Klasse überschreiben, müssen Sie die OnItemCreated(SiteMapNodeItemEventArgs)-Methode der Basisklasse aufrufen, damit registrierte Delegaten das Ereignis empfangen.When overriding OnItemCreated(SiteMapNodeItemEventArgs) in a derived class, be sure to call the base class's OnItemCreated(SiteMapNodeItemEventArgs) method so that registered delegates receive the event.

Applies to

See also