Saturday 12 October 2013

How to retrieve sharepoint List data and bind its field to DropdownList Programmatically?


Using SPListItemCollection class :

                string siteUrl = SPContext.Current.Web.Url;
                using (SPSite spsite = new SPSite(siteUrl))
                {
                    using (SPWeb spweb = spsite.OpenWeb())
                    {
                        SPList myList= spweb.Lists["ListName"];
                        SPListItemCollection items = myList.GetItems();
                        dropdownlist.DataSource = items;
                        dropdownlist.DataTextField = "FieldName"; //List field holding name
                        dropdownlist.DataValueField = "FieldName"; //List field holding value
                        dropdownlist.DataBind();
                    }
                }

No comments:

Post a Comment

Total Pageviews