How to Bind SharePoint Lists into a DropDown in SharePoint 2010/2013?

Hello SharePointers,

In this blog, I will give the source code to bind the asp.net dropdownlist with the SharePoint list names in SharePoint 2013. Below are the source code to achieve the same.

//Create a Asp.Net Dropdown list one for list and one for list items.

DropDownList ddlSPLists;
DropDownList ddlListItems;

ddlSPLists = new DropDownList();
ddlSPLists.ID = “ddlSPLists”;
ddlSPLists.AutoPostBack = true;
ddlSPLists.SelectedIndexChanged += ddl_SelectedIndexChanged;
// Get the Collection of the Lists in a current site.
SPListCollection lists = SPContext.Current.Web.Lists;
foreach (SPList list in lists)
ddlSPLists.Items.Add(new ListItem(list.Title, list.ID.ToString()));
Controls.Add(ddlSPLists);
ddlListItems = new DropDownList();
ddlListItems.ID = “ddlListItemTitle”;
ddlListItems.SelectedIndexChanged += ddlListItems_SelectedIndexChanged;
ddlListItems.AutoPostBack = true;
Controls.Add(ddlListItems);

Happy SharePointing folks!! Hope it helps you!!

Leave a Reply

Your email address will not be published. Required fields are marked *