SiteMapNodeCollection 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 SiteMapNodeCollection 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| 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集合,然後用該SiteMapNodeCollection方法將元素加入 。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
備註
使用 SiteMapNodeCollection 建構函式建立一個空 SiteMapNodeCollection 集合。 你可以用 SiteMapNodeCollection、 Add或 AddRange 方法來Insert加入元素。
另請參閱
適用於
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
SiteMapNode A SiteMapNodeCollection補充到 。
例外狀況
value 是 null。
範例
以下程式碼範例示範如何建立SiteMapNodeCollection一個包含單一初始SiteMapNode物件的集合,然後利用該SiteMapNodeCollection方法將 a SiteMapNode of AddRange 物件加入其中。 你可以修改 SiteMapNodeCollection,即使個別 SiteMapNode 物件可能是唯讀。
// 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 物件的集合。 你可以用 SiteMapNodeCollection、 Add或 AddRange 方法來Insert加入元素。
另請參閱
適用於
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。
例外狀況
value 是 null。
備註
使用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)
參數
- value
- SiteMapNodeCollection
SiteMapNodeCollection A 包含 SiteMapNode 將 加到 電流 SiteMapNodeCollection。
例外狀況
value 是 null。
範例
以下程式碼範例示範如何以另一個SiteMapNodeCollectionSiteMapNodeCollection物件作為基礎來建立SiteMapNode集合。 該 SiteMapNode.GetAllNodes 方法回傳一個唯讀 SiteMapNodeCollection,當屬性 IsReadOnly 返回 true時會偵測到。 使用唯讀SiteMapNodeCollection建立一個新方法SiteMapNodeCollection,且Add可成功呼叫 and 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
備註
使用SiteMapNodeCollection建構子等同於呼叫SiteMapNodeCollection建構子並用該SiteMapNodeCollection方法向集合中加入元素AddRange。