SharePoint 2013 - SPLessons

SharePoint List Data

Home > Lesson > Chapter 29
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SharePoint List Data

SharePoint List Data

Get The list items from the sharepoint list, Here am getting data from the Splessons List , and then data was binding into the the Dropdown. [csharp]private void GetListItems() { try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite oSite = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb objWeb = oSite.OpenWeb()) { SPList oList = objWeb.Lists["Splessons"]; SPListItemCollection oListCollection = oList.GetItems(); ddlLocation.DataSource = oListCollection.GetDataTable(); ddlLocation.DataValueField = "ID"; ddlLocation.DataTextField = "Location"; ddlLocation.DataBind(); } } }); } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(typeof(SPAlert), "alert", "<script language="\&quot;javascript\&quot;"></script>"); } } [/csharp]