SPListItemCollection.Delete 方法
Deletes the item at the specified index in the collection.
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub Delete ( _
iIndex As Integer _
)
用法
Dim instance As SPListItemCollection
Dim iIndex As Integer
instance.Delete(iIndex)
public void Delete(
int iIndex
)
参数
iIndex
类型:System.Int32A 32-bit integer that specifies the index.
备注
The Delete method deletes an item based on its index in the collection. To delete an item based on its ID, use the DeleteItemById method.
This method returns an ArgumentOutOfRangeException exception if the specified index is outside the valid range of indices for the collection.
示例
The following code example deletes any items from the specified list in which an integer field value is less than 70 or a text field value equals None.
The For loop in the example counts downward (intindex-- ) instead of upward (intindex++ ) because items are being deleted and the number of items decreases with each increment.
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim srcList As SPList = site.Lists("List_Name")
Dim listItems As SPListItemCollection = srcList.Items
Dim intIndex As Integer
For intIndex = listItems.Count - 1 To 0 Step -1
If Convert.ToInt32(listItems(intIndex)("Field1_Name")) < 70 _
OrElse listItems(intIndex)("Field2_Name").ToString() = "None" Then
listItems.Delete(intIndex)
End If
Next i
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["List_Name"];
SPListItemCollection collListItems = oList.Items;
for (int intIndex = collListItems.Count - 1; intIndex > -1; intIndex--)
{
if (Convert.ToInt32(collListItems[intIndex]["Field1_Name"]) < 70 ||
collListItems[intIndex]["Field2_Name"].ToString() == "None")
{
collListItems.Delete(intIndex);
}
}