Share via


SiteMapNodeCollection Konstruktory

Definice

Inicializuje novou instanci SiteMapNodeCollection třídy .

Přetížení

SiteMapNodeCollection()

Inicializuje novou instanci SiteMapNodeCollection třídy , což je výchozí instance.

SiteMapNodeCollection(Int32)

Inicializuje novou instanci SiteMapNodeCollection třídy se zadanou počáteční kapacitou.

SiteMapNodeCollection(SiteMapNode)

Inicializuje novou instanci SiteMapNodeCollection třídy a přidá SiteMapNode objekt do InnerList vlastnosti kolekce.

SiteMapNodeCollection(SiteMapNode[])

Inicializuje novou instanci SiteMapNodeCollection třídy a přidá pole typu SiteMapNode do InnerList vlastnosti kolekce.

SiteMapNodeCollection(SiteMapNodeCollection)

Inicializuje novou instanci SiteMapNodeCollection třídy a přidá všechny položky seznamu zadané SiteMapNodeCollection kolekce do InnerList vlastnosti kolekce.

SiteMapNodeCollection()

Inicializuje novou instanci SiteMapNodeCollection třídy , což je výchozí instance.

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

Příklady

Následující příklad kódu ukazuje, jak pomocí konstruktoru SiteMapNodeCollection vytvořit novou SiteMapNodeCollection kolekci a poté přidat elementy do SiteMapNodeCollection pomocí Add metody .

// The LoadSiteMapData() method loads site navigation
// data from persistent storage into a DataTable.
DataTable siteMap = LoadSiteMapData();

// Create a SiteMapNodeCollection.
SiteMapNodeCollection nodes = new SiteMapNodeCollection();

// Create a SiteMapNode and add it to the collection.
SiteMapNode tempNode;
DataRow row;
int index = 0;

while (index < siteMap.Rows.Count)
{

    row = siteMap.Rows[index];

    // Create a node based on the data in the DataRow.
    tempNode = new SiteMapNode(SiteMap.Provider,
                                row["Key"].ToString(),
                                row["Url"].ToString());

    // Add the node to the collection.
    nodes.Add(tempNode);
    ++index;
}
' The LoadSiteMapData() Function loads site navigation
' data from persistent storage into a DataTable.

Dim siteMapData As DataTable
siteMapData = LoadSiteMapData()

' Create a SiteMapNodeCollection.
Dim nodes As New SiteMapNodeCollection()

' Create a SiteMapNode and add it to the collection.
Dim tempNode As SiteMapNode
Dim row As DataRow
Dim index As Integer
index = 0

While (index < siteMapData.Rows.Count)

    row = siteMapData.Rows(index)

    ' Create a node based on the data in the DataRow.
    tempNode = New SiteMapNode(SiteMap.Provider, row("Key").ToString(), row("Url").ToString())

    ' Add the node to the collection.
    nodes.Add(tempNode)
    index = index + 1
End While

Poznámky

Pomocí konstruktoru SiteMapNodeCollection vytvořte prázdnou SiteMapNodeCollection kolekci. Elementy můžete do objektu SiteMapNodeCollection přidat pomocí Addmetody , AddRangenebo Insert .

Viz také

Platí pro

SiteMapNodeCollection(Int32)

Inicializuje novou instanci SiteMapNodeCollection třídy se zadanou počáteční kapacitou.

public:
 SiteMapNodeCollection(int capacity);
public SiteMapNodeCollection (int capacity);
new System.Web.SiteMapNodeCollection : int -> System.Web.SiteMapNodeCollection
Public Sub New (capacity As Integer)

Parametry

capacity
Int32

Počáteční kapacita nástroje SiteMapNodeCollection.

Poznámky

Pomocí konstruktoru SiteMapNodeCollection vytvořte kolekci se zadanou SiteMapNodeCollection počáteční kapacitou.

Viz také

Platí pro

SiteMapNodeCollection(SiteMapNode)

Inicializuje novou instanci SiteMapNodeCollection třídy a přidá SiteMapNode objekt do InnerList vlastnosti kolekce.

public:
 SiteMapNodeCollection(System::Web::SiteMapNode ^ value);
public SiteMapNodeCollection (System.Web.SiteMapNode value);
new System.Web.SiteMapNodeCollection : System.Web.SiteMapNode -> System.Web.SiteMapNodeCollection
Public Sub New (value As SiteMapNode)

Parametry

value
SiteMapNode

A SiteMapNode pro přidání do SiteMapNodeCollection.

Výjimky

value je null.

Příklady

Následující příklad kódu ukazuje, jak vytvořit SiteMapNodeCollection kolekci s jedním počátečním SiteMapNode objektem a poté přidat SiteMapNodeCollectionSiteMapNode objekt objektů do něj pomocí AddRange metody . Můžete upravit SiteMapNodeCollection, i když jednotlivé SiteMapNode objekty můžou být jen pro čtení.


// Create a SiteMapNodeCollection with all the nodes
// from the first two hierarchical levels of the current
// site map.
SiteMapNodeCollection baseCollection =
    new SiteMapNodeCollection(SiteMap.RootNode);

SiteMapNodeCollection childCollection =
    SiteMap.RootNode.ChildNodes;

baseCollection.AddRange(childCollection);

Response.Write( "<BR>Derived SiteMapNodeCollection.<BR><HR><BR>");
foreach (SiteMapNode node in baseCollection) {
    Response.Write( node.Title + "<BR>");
}

' Create a SiteMapNodeCollection with all the nodes
' from the first two hierarchical levels of the current
' site map.
Dim baseCollection As SiteMapNodeCollection
baseCollection = New SiteMapNodeCollection(SiteMap.RootNode)

Dim childCollection As SiteMapNodeCollection = SiteMap.RootNode.ChildNodes

baseCollection.AddRange(childCollection)

Response.Write( "<BR>Derived SiteMapNodeCollection.<BR><HR><BR>")

For Each node In baseCollection
    Response.Write( node.Title + "<BR>")
Next

Poznámky

Pomocí konstruktoru SiteMapNodeCollection vytvořte kolekci SiteMapNodeCollection s jedním počátečním SiteMapNode objektem. Elementy můžete do objektu SiteMapNodeCollection přidat pomocí Addmetody , AddRangenebo Insert .

Viz také

Platí pro

SiteMapNodeCollection(SiteMapNode[])

Inicializuje novou instanci SiteMapNodeCollection třídy a přidá pole typu SiteMapNode do InnerList vlastnosti kolekce.

public:
 SiteMapNodeCollection(cli::array <System::Web::SiteMapNode ^> ^ value);
public SiteMapNodeCollection (System.Web.SiteMapNode[] value);
new System.Web.SiteMapNodeCollection : System.Web.SiteMapNode[] -> System.Web.SiteMapNodeCollection
Public Sub New (value As SiteMapNode())

Parametry

value
SiteMapNode[]

Pole typu SiteMapNode , které se má přidat do SiteMapNodeCollection.

Výjimky

value je null.

Poznámky

Použití konstruktoru SiteMapNodeCollection je ekvivalentem volání konstruktoru SiteMapNodeCollection a přidání elementů SiteMapNodeCollection do kolekce pomocí AddRange metody .

Viz také

Platí pro

SiteMapNodeCollection(SiteMapNodeCollection)

Inicializuje novou instanci SiteMapNodeCollection třídy a přidá všechny položky seznamu zadané SiteMapNodeCollection kolekce do InnerList vlastnosti kolekce.

public:
 SiteMapNodeCollection(System::Web::SiteMapNodeCollection ^ value);
public SiteMapNodeCollection (System.Web.SiteMapNodeCollection value);
new System.Web.SiteMapNodeCollection : System.Web.SiteMapNodeCollection -> System.Web.SiteMapNodeCollection
Public Sub New (value As SiteMapNodeCollection)

Parametry

value
SiteMapNodeCollection

A SiteMapNodeCollection obsahující objekt , který SiteMapNode se má přidat k aktuálnímu SiteMapNodeCollectionobjektu .

Výjimky

value je null.

Příklady

Následující příklad kódu ukazuje, jak vytvořit kolekci SiteMapNodeCollection pomocí jiné SiteMapNodeCollection z SiteMapNode objektů jako základ. Metoda SiteMapNode.GetAllNodes vrátí objekt jen SiteMapNodeCollectionpro čtení, který se zjistí, když IsReadOnly vlastnost vrátí truehodnotu . Nový SiteMapNodeCollection se vytvoří pomocí metody jen pro SiteMapNodeCollection čtení a Add lze úspěšně volat metody a Remove .

SiteMapNodeCollection siteNodes = SiteMap.RootNode.GetAllNodes();

if ( siteNodes.IsReadOnly ||
     siteNodes.IsFixedSize )
{
    Response.Write("Collection is read-only or has fixed size.<BR>");

    // Create a new, modifiable collection from the existing one.
    SiteMapNodeCollection modifiableCollection =
         new SiteMapNodeCollection(siteNodes);

    // The MoveNode example method moves a node from position one to
    // the last position in the collection.
    MoveNode(modifiableCollection);
}
else {
    MoveNode(siteNodes);
}

Dim siteNodes As SiteMapNodeCollection
siteNodes = SiteMap.RootNode.GetAllNodes()

If siteNodes.IsReadOnly Or siteNodes.IsFixedSize Then

    Response.Write("Collection is read-only or has fixed size.<BR>")

    ' Create a new, modifiable collection from the existing one.
    Dim modifiableCollection As SiteMapNodeCollection
    modifiableCollection = New SiteMapNodeCollection(siteNodes)

    ' The MoveNode example method moves a node from position one to
    ' the last position in the collection.
    MoveNode(modifiableCollection)
Else
    MoveNode(siteNodes)
End If

Poznámky

Použití konstruktoru SiteMapNodeCollection je ekvivalentem volání konstruktoru SiteMapNodeCollection a přidání elementů SiteMapNodeCollection do kolekce pomocí AddRange metody .

Platí pro