Export (0) Print
Expand All

SPListItemCollection.GetDataTable method

Returns the collection of list items as a data table.

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

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.

SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["List_Name"];
SPListItemCollection collListItems = oList.Items;

DataGrid1.DataSource = collListItems.GetDataTable();
DataGrid1.DataBind();
Show:
© 2014 Microsoft