Question

I am developing an app for my site. I have an external list that displays all the data i need fine. I need to somehow get that data in Visual Studio 2013 so i can loop through the data and create a dynamic dropdown (<select>). Any documentation or help is greatly appreciated.

Était-ce utile?

La solution

So remember, for all intents and purposes, an External list, for all that it gets its data from an external source is still a SharePoint list.

If I am url is spSnippet.com, external list is called ExternalList and the field I need is FieldForDropdown (real imaginative I know) then my code is simply:

using(SPSite spSite = new SPSite("http://spSnippet.com"))
{
  using(SPWeb spWeb = spSite.RootWeb)
  {
    SPList spExternalList = spWeb.GetList("/Lists/ExternalList");
    List<string> dropdownList = new List<string>();

    foreach(SPListItem spItem in spExternalList.Items)
    {
        dropdownList.Add(spItem["FieldForDropdown"].ToString());
    }
  }
}

You can now use the list dropdownList to build your drop down as needed.

Please note: this is just code I threw together and hasn't been tested. You will likely need to modify for your needs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top