SiteMapNodeCollection 建構函式

定義

初始化 SiteMapNodeCollection 類別的新執行個體。

多載

SiteMapNodeCollection()

初始化 SiteMapNodeCollection 類別的新執行個體,這個執行個體是預設的。

SiteMapNodeCollection(Int32)

使用指定的初始容量,初始化 SiteMapNodeCollection 類別的新執行個體。

SiteMapNodeCollection(SiteMapNode)

初始化 SiteMapNodeCollection 類別的新執行個體,並將 SiteMapNode 物件加入至集合的 InnerList 屬性。

SiteMapNodeCollection(SiteMapNode[])

初始化 SiteMapNodeCollection 類別的新執行個體,並將 SiteMapNode 型別陣列加入至集合的 InnerList 屬性。

SiteMapNodeCollection(SiteMapNodeCollection)

初始化 SiteMapNodeCollection 類別的新執行個體,並將指定之 SiteMapNodeCollection 集合的所有清單項目加入至集合的 InnerList 屬性。

SiteMapNodeCollection()

初始化 SiteMapNodeCollection 類別的新執行個體,這個執行個體是預設的。

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

範例

下列程式碼範例示範如何使用 SiteMapNodeCollection 建構函式來建立新的 SiteMapNodeCollection 集合,然後使用 方法將元素新增至 SiteMapNodeCollectionAdd

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

備註

使用 建 SiteMapNodeCollection 構函式來建立空 SiteMapNodeCollection 的集合。 您可以使用 、 或 方法,將元素新增至 SiteMapNodeCollectionAddInsertAddRange

另請參閱

適用於

SiteMapNodeCollection(Int32)

使用指定的初始容量,初始化 SiteMapNodeCollection 類別的新執行個體。

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

參數

capacity
Int32

SiteMapNodeCollection 的初始容量。

備註

使用 建 SiteMapNodeCollection 構函式來建立 SiteMapNodeCollection 具有指定初始容量的集合。

另請參閱

適用於

SiteMapNodeCollection(SiteMapNode)

初始化 SiteMapNodeCollection 類別的新執行個體,並將 SiteMapNode 物件加入至集合的 InnerList 屬性。

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)

參數

value
SiteMapNode

要加入至 SiteMapNodeCollectionSiteMapNode

例外狀況

valuenull

範例

下列程式碼範例示範如何使用單一初始物件建立 SiteMapNodeCollection 集合,然後使用 方法將 物件的 SiteMapNode 加入 SiteMapNodeCollection 其中 AddRangeSiteMapNode 即使個別 SiteMapNode 物件可能是唯讀的,您也可以修改 SiteMapNodeCollection


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

備註

使用 建 SiteMapNodeCollection 構函式建立 SiteMapNodeCollection 具有單一初始 SiteMapNode 物件的集合。 您可以使用 、 或 方法,將元素新增至 SiteMapNodeCollectionAddInsertAddRange

另請參閱

適用於

SiteMapNodeCollection(SiteMapNode[])

初始化 SiteMapNodeCollection 類別的新執行個體,並將 SiteMapNode 型別陣列加入至集合的 InnerList 屬性。

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

參數

value
SiteMapNode[]

要加入至 SiteMapNode 中的 SiteMapNodeCollection 型別陣列。

例外狀況

valuenull

備註

使用 建 SiteMapNodeCollection 構函式相當於呼叫建構函式, SiteMapNodeCollection 並使用 方法將元素 SiteMapNodeCollection 加入至集合 AddRange

另請參閱

適用於

SiteMapNodeCollection(SiteMapNodeCollection)

初始化 SiteMapNodeCollection 類別的新執行個體,並將指定之 SiteMapNodeCollection 集合的所有清單項目加入至集合的 InnerList 屬性。

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)

參數

例外狀況

valuenull

範例

下列程式碼範例示範如何使用另一個 SiteMapNodeCollectionSiteMapNode 物件做為基底來建立 SiteMapNodeCollection 集合。 方法 SiteMapNode.GetAllNodes 會傳回唯讀 SiteMapNodeCollection 的 ,當 屬性傳 true 回 時 IsReadOnly ,會偵測到這個屬性。 使用唯讀建立新的 SiteMapNodeCollection ,而且 Add 可以成功呼叫 和 RemoveSiteMapNodeCollection 方法。

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

備註

使用 建 SiteMapNodeCollection 構函式相當於呼叫建構函式, SiteMapNodeCollection 並使用 方法將元素 SiteMapNodeCollection 加入至集合 AddRange

適用於