Share via


SiteMapPath.InitializeItem(SiteMapNodeItem) Método

Definición

Rellena SiteMapNodeItem, que es un control de servidor Web que representa SiteMapNode, con un conjunto de controles secundarios basándose en la función del nodo y en las plantillas y estilos especificados para el nodo.

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

Parámetros

item
SiteMapNodeItem

SiteMapNodeItem que se va a inicializar.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el InitializeItem método para agregar funcionalidad a un control que deriva de SiteMapPath. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la SiteMapPath clase .

// Override the InitializeItem method to add a PathSeparator
// and DropDownList to the current node.
protected override void InitializeItem(SiteMapNodeItem item) {

    // The only node that must be handled is the CurrentNode.
    if (item.ItemType == SiteMapNodeItemType.Current)
    {
        HyperLink hLink = new HyperLink();

        // No Theming for the HyperLink.
        hLink.EnableTheming = false;
        // Enable the link of the SiteMapPath is enabled.
        hLink.Enabled = this.Enabled;

        // Set the properties of the HyperLink to
        // match those of the corresponding SiteMapNode.
        hLink.NavigateUrl = item.SiteMapNode.Url;
        hLink.Text        = item.SiteMapNode.Title;
        if (ShowToolTips) {
            hLink.ToolTip = item.SiteMapNode.Description;
        }

        // Apply styles or templates to the HyperLink here.
        // ...
        // ...

        // Add the item to the Controls collection.
        item.Controls.Add(hLink);

        AddDropDownListAfterCurrentNode(item);
    }
    else {
        base.InitializeItem(item);
    }
}
' Override the InitializeItem method to add a PathSeparator
' and DropDownList to the current node.
Protected Overrides Sub InitializeItem(item As SiteMapNodeItem)

   ' The only node that must be handled is the CurrentNode.
   If item.ItemType = SiteMapNodeItemType.Current Then
      Dim hLink As New HyperLink()

      ' No Theming for the HyperLink.
      hLink.EnableTheming = False
      ' Enable the link of the SiteMapPath is enabled.
      hLink.Enabled = Me.Enabled

      ' Set the properties of the HyperLink to
      ' match those of the corresponding SiteMapNode.
      hLink.NavigateUrl = item.SiteMapNode.Url
      hLink.Text = item.SiteMapNode.Title
      If ShowToolTips Then
         hLink.ToolTip = item.SiteMapNode.Description
      End If

      ' Apply styles or templates to the HyperLink here.
      ' ...
      ' ...
      ' Add the item to the Controls collection.
      item.Controls.Add(hLink)

      AddDropDownListAfterCurrentNode(item)
   Else
      MyBase.InitializeItem(item)
   End If
End Sub

Comentarios

El InitializeItem método determina el tipo funcional de nodo que representa el elemento comprobando SiteMapNodeItemTypey aplica las plantillas o estilos definidos para ese tipo de nodo.

SiteMapNodeItem Si tiene un Root tipo de elemento, se crea un HyperLink control secundario y se puede aplicar y RootNodeTemplate RootNodeStyle . RootNodeTemplate Si se establece , ITemplate se aplica al nodo . En su lugar, RootNodeStyle se establece , se combina con cualquier definido NodeStyle y aplicado. Por último, si no se definen plantillas o estilos, se crea un control básico HyperLink y se inicializa con valores del nodo.

SiteMapNodeItem Si tiene un Current tipo de elemento, se crea un Literal control secundario o HyperLink , en función del valor devuelto de RenderCurrentNodeAsLink. A continuación, se puede aplicar o CurrentNodeTemplate CurrentNodeStyle . CurrentNodeTemplate Si se establece , ITemplate se aplica al nodo . Si en su lugar CurrentNodeStyle se establece , se combina con cualquier definido NodeStyle y aplicado.

SiteMapNodeItem Si tiene un Parent tipo de elemento, se crea un HyperLink control secundario y se puede aplicar y NodeTemplate NodeStyle . NodeTemplate Si se establece , ITemplate se aplica al nodo . Si en su lugar NodeStyle se establece , se aplica.

Por último, si SiteMapNodeItem tiene un PathSeparator tipo de elemento, se crea un Literal control secundario y y PathSeparatorStyle PathSeparatorTemplate se aplican según las mismas reglas generales definidas para un Parent tipo de nodo.

Invalide el InitializeItem método para manipular objetos individuales SiteMapNodeItem . Si el diseño de la clase requiere un control más amplio sobre cómo se crean y agregan los SiteMapNodeItem objetos al SiteMapPath control, invalide el CreateControlHierarchy método .

Se aplica a

Consulte también