다음을 통해 공유


SPListItemCollection.GetDataTable Method

Returns the collection of list items as a data table.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Function GetDataTable As DataTable
'Usage
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.

Examples

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()
DataGrid1.DataBind() 
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["List_Name"];
SPListItemCollection collListItems = oList.Items;

DataGrid1.DataSource = collListItems.GetDataTable();
DataGrid1.DataBind();

See Also

Reference

SPListItemCollection Class

SPListItemCollection Members

Microsoft.SharePoint Namespace