Sdílet prostřednictvím


SiteMapNodeCollection Konstruktory

Definice

Inicializuje novou instanci SiteMapNodeCollection třídy.

Přetížení

Name Description
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í SiteMapNodeCollection konstruktoru vytvořit novou SiteMapNodeCollection kolekci a pak přidat elementy SiteMapNodeCollection do metody Add .

// 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. K použití Add, AddRangenebo Insert metody můžete přidat prvkySiteMapNodeCollection.

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 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 pak do něj přidat SiteMapNodeCollection objekty SiteMapNode pomocí AddRange metody. Můžete upravit SiteMapNodeCollection, i když jednotlivé SiteMapNode objekty mohou 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. K použití Add, AddRangenebo Insert metody můžete přidat prvkySiteMapNodeCollection.

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é chcete přidat do objektu SiteMapNodeCollection.

Výjimky

value je null.

Poznámky

SiteMapNodeCollection Použití konstruktoru je ekvivalentní volání SiteMapNodeCollection konstruktoru 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 , který obsahuje SiteMapNode přidat do aktuálního SiteMapNodeCollection.

Výjimky

value je null.

Příklady

Následující příklad kódu ukazuje, jak vytvořit SiteMapNodeCollection kolekci pomocí jiného SiteMapNodeCollection objektu SiteMapNode jako základ. Metoda SiteMapNode.GetAllNodes vrátí jen SiteMapNodeCollectionpro čtení , která je zjištěna při IsReadOnly vrácení truevlastnosti . Vytvoří se nový SiteMapNodeCollection pomocí jen SiteMapNodeCollection pro čtení a Add metody lze Remove úspěšně volat.

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

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

Platí pro