Uredi

Deli z drugimi prek


SiteMapNodeCollection Constructors

Definition

Initializes a new instance of the SiteMapNodeCollection class.

Overloads

SiteMapNodeCollection()

Initializes a new instance of the SiteMapNodeCollection class, which is the default instance.

SiteMapNodeCollection(Int32)

Initializes a new instance of the SiteMapNodeCollection class with the specified initial capacity.

SiteMapNodeCollection(SiteMapNode)

Initializes a new instance of the SiteMapNodeCollection class and adds the SiteMapNode object to the InnerList property for the collection.

SiteMapNodeCollection(SiteMapNode[])

Initializes a new instance of the SiteMapNodeCollection class and adds the array of type SiteMapNode to the InnerList property for the collection.

SiteMapNodeCollection(SiteMapNodeCollection)

Initializes a new instance of the SiteMapNodeCollection class and adds all the list items of the specified SiteMapNodeCollection collection to the InnerList property for the collection.

SiteMapNodeCollection()

Initializes a new instance of the SiteMapNodeCollection class, which is the default instance.

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

Examples

The following code example demonstrates how to use the SiteMapNodeCollection constructor to create a new SiteMapNodeCollection collection, and then add elements to the SiteMapNodeCollection with the Add method.

// 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

Remarks

Use the SiteMapNodeCollection constructor to create an empty SiteMapNodeCollection collection. You can add elements to the SiteMapNodeCollection using the Add, AddRange, or Insert method.

See also

Applies to

SiteMapNodeCollection(Int32)

Initializes a new instance of the SiteMapNodeCollection class with the specified initial capacity.

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

Parameters

capacity
Int32

The initial capacity of the SiteMapNodeCollection.

Remarks

Use the SiteMapNodeCollection constructor to create a SiteMapNodeCollection collection with the specified initial capacity.

See also

Applies to

SiteMapNodeCollection(SiteMapNode)

Initializes a new instance of the SiteMapNodeCollection class and adds the SiteMapNode object to the InnerList property for the collection.

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)

Parameters

Exceptions

value is null.

Examples

The following code example demonstrates how to create a SiteMapNodeCollection collection with a single initial SiteMapNode object, and then add a SiteMapNodeCollection of SiteMapNode objects to it using the AddRange method. You can modify the SiteMapNodeCollection, even though the individual SiteMapNode objects might be read-only.


// 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

Remarks

Use the SiteMapNodeCollection constructor to create a SiteMapNodeCollection collection with a single initial SiteMapNode object. You can add elements to the SiteMapNodeCollection using the Add, AddRange, or Insert method.

See also

Applies to

SiteMapNodeCollection(SiteMapNode[])

Initializes a new instance of the SiteMapNodeCollection class and adds the array of type SiteMapNode to the InnerList property for the collection.

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())

Parameters

value
SiteMapNode[]

An array of type SiteMapNode to add to the SiteMapNodeCollection.

Exceptions

value is null.

Remarks

Using the SiteMapNodeCollection constructor is equivalent to calling the SiteMapNodeCollection constructor and adding elements to the SiteMapNodeCollection collection with the AddRange method.

See also

Applies to

SiteMapNodeCollection(SiteMapNodeCollection)

Initializes a new instance of the SiteMapNodeCollection class and adds all the list items of the specified SiteMapNodeCollection collection to the InnerList property for the collection.

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)

Parameters

value
SiteMapNodeCollection

A SiteMapNodeCollection that contains the SiteMapNode to add to the current SiteMapNodeCollection.

Exceptions

value is null.

Examples

The following code example demonstrates how to create a SiteMapNodeCollection collection using another SiteMapNodeCollection of SiteMapNode objects as a base. The SiteMapNode.GetAllNodes method returns a read-only SiteMapNodeCollection, which is detected when the IsReadOnly property returns true. A new SiteMapNodeCollection is created using the read-only SiteMapNodeCollection and the Add and Remove methods can be called successfully.

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

Remarks

Using the SiteMapNodeCollection constructor is equivalent to calling the SiteMapNodeCollection constructor and adding elements to the SiteMapNodeCollection collection with the AddRange method.

Applies to