Friday, 21 March 2014

Retrieve ListItem data Using CAML in SharePoint 2013

The following code snippet can be used to programmatically retrieve list item data Using CAML

 SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["Documents"];
            SPQuery query = new SPQuery();
            query.ViewFields = "<FieldRef Name='ID'/>" +"<FieldRef Name='Title'/>" + "<FieldRef Name='LastName'/>" +"<FieldRef Name='Age'/>";
            SPListItemCollection item = list.GetItems(query);
            GridView1.DataSource = item.GetDataTable();
            GridView1.DataBind();


No comments:

Post a comment