Pages

Showing posts with label list column data to drop down. Show all posts
Showing posts with label list column data to drop down. Show all posts

Sunday, 26 August 2012

Retrieve SharePoint List Data and bind this to a dropdownlist

To bind the drop down list data with a field from the SharePoint list you can use the below code methods:-
Method 1
       
if (!Page.IsPostBack)
        {
            using (SPSite site = new ("http://yoursharepointsite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["NameOfYourList"];
                    dropSite.DataSource = list.Items;
                    dropSite.DataValueField = "Title"; // List field holding value - first column is called Title anyway!
                    dropSite.DataTextField = "Title"; // List field holding name to be displayed on page 
                    dropSite.DataBind();
                }
            }
        }



Method 2:- Using SPDataSource


Popular Posts