This documentation is archived and is not being maintained.
ListItemCollection.AddRange Method
.NET Framework 1.1
Adds the items in an array of ListItem objects to the collection.
[Visual Basic] Public Sub AddRange( _ ByVal items() As ListItem _ ) [C#] public void AddRange( ListItem[] items ); [C++] public: void AddRange( ListItem* items[] ); [JScript] public function AddRange( items : ListItem[] );
Parameters
- items
- An array of ListItem objects that contain the items to add to the collection.
Remarks
Use the AddRange method to add the items in the array of ListItem objects specified by the items parameter. This allows you to add multiple ListItem objects to the collection in a single step.
Example
[Visual Basic] Dim MyListItemCollection As ListItemCollection = New ListItemCollection() ' Dimensions an array of ListItems that are used to populate the collection. Dim NewListItemArray(TempDataTable.Count - 1) As System.Web.UI.WebControls.ListItem ' Populates the array of ListItems with generic data. Dim i As Integer For i = 0 To TempDataTable.Count - 1 NewListItemArray(i) = New ListItem() NewListItemArray(i).Text = "Item " + i.ToString() NewListItemArray(i).Value = i.ToString() Next ' Adds an entire array of ListItem objects to the collection. MyListItemCollection.AddRange(NewListItemArray) [C#] ListItemCollection myListItemCollection = new ListItemCollection(); // Creates an array of ListItems that are used to populate the collection. System.Web.UI.WebControls.ListItem[] newListItemArray = new ListItem[tempDataTable.Count]; // Populates the array of ListItems with generic data. for (int i=0; i < tempDataTable.Count; i++) { newListItemArray[i] = new ListItem(); newListItemArray[i].Text = "Item " + i.ToString(); newListItemArray[i].Value = i.ToString(); } // Adds an entire array of ListItem objects to the collection. myListItemCollection.AddRange(newListItemArray); [C++] ListItemCollection* myListItemCollection = new ListItemCollection(); // Creates an array of ListItems that are used to populate the collection. System::Web::UI::WebControls::ListItem* newListItemArray[] = new ListItem*[tempDataTable->Count]; // Populates the array of ListItems with generic data. for (int i=0; i < tempDataTable->Count; i++) { newListItemArray[i] = new ListItem(); newListItemArray[i]->Text = String::Format( S"Item {0}", __box(i)); newListItemArray[i]->Value = i.ToString(); } // Adds an entire array of ListItem objects to the collection. myListItemCollection->AddRange(newListItemArray);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
ListItemCollection Class | ListItemCollection Members | System.Web.UI.WebControls Namespace | ListItem | Add | Insert | Remove | RemoveAt | Clear
Show: