Share via

SPListItemCollection.GetDataTable method

Returns the collection of list items as a data table.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Public Function GetDataTable As DataTable
Dim instance As SPListItemCollection
Dim returnValue As DataTable

returnValue = instance.GetDataTable()
public DataTable GetDataTable()

Return value

Type: System.Data.DataTable
A System.Data.DataTable object that contains the list items.


The following code example uses the GetDataTable method to display items in a DataGrid control.

The example assumes the existence of an .aspx page that contains a DataGrid control.

Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim list As SPList = site.Lists("List_Name")
Dim listItems As SPListItemCollection = list.Items

DataGrid1.DataSource = listItems.GetDataTable()
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["List_Name"];
SPListItemCollection collListItems = oList.Items;

DataGrid1.DataSource = collListItems.GetDataTable();

See also


SPListItemCollection class

SPListItemCollection members

Microsoft.SharePoint namespace