using Microsoft.SharePoint;
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = SPContext.Current.Web;
SPList splst = myWeb.Lists["LIST
NAME"];
SPListItemCollection splstitemcollection = splst.Items;
//create datatable
DataTable dt = new
DataTable();
dt.Columns.Add("COLUMN
NAME1");
dt.Columns.Add("COLUMN
NAME2");
dt.Columns.Add("COLUMN
NAME3");
DataRow dr;
foreach (SPListItem
splstitem in splstitemcollection)
{
dr = dt.NewRow();
dr["COLUMN NAME1"]
= splstitem["LIST COLUMN NAME1"];
dr["COLUMN NAME2"]
= splstitem["LIST COLUMN NAME2"];
dr["COLUMN NAME3"]
= splstitem["LIST COLUMN NAME1"];
dt.Rows.Add(dr);
}
if (dt.Rows.Count > 0)
{
//bind your grid here.
grd.DataSource = dt;
grd.DataBind();
}
No comments:
Post a Comment