Saturday, June 13, 2009
Reading data from sharepoint customlist
Here I explained a simple program for sharepoint beginners which states that reading a data from custom list and bind it to a dropdownlist.
first we have to add microsoft sharepoint dll to our application and import the following name space.
using Microsoft.SharePoint;
declare the following parameters globally.
SPSite objSite;
SPWeb oWeb;
SPList regList;
and bind the data like this
objSite = new SPSite(SPContext.Current.Site.ID);
oWeb = objSite.OpenWeb("/sitename/");
regList = oWeb.Lists["listname"];
SPListItemCollection oItems = regList.Items;
dt = new DataTable();
dt = oItems.GetDataTable();
ddlTypeCourses.DataSource = dt;
ddlTypeCourses.DataTextField = "Title";
ddlTypeCourses.DataValueField = "Title";
//ddlTypeCourses.Items.Add(new ListItem("-select-", "0"));
ddlTypeCourses.DataBind();
ddlTypeCourses.Items.Insert(0, new ListItem("---Select Course Types---", "0"));
Labels:
customlist,
dropdownlist,
sharepoint,
splist,
spsite,
wss3.0.sharepoint
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment