1

I want to fetch all the list titles of the current site in a dropdown in my web part's editor part. Based on this selection I want to show list items in web part when Apply is hit.

My web part is deployed at site collections level.

2 Answers 2

1

Get the List title source:

public static IList<String> GetAllListTitle(SPWeb web)
{
    List<String> title = new List<String>();

    foreach(SPList list in web.Lists)
      title.Items.Add(list.Title)
}

Have a look at these for how to implement dynamic dropdown as webpart property.

http://social.msdn.microsoft.com/Forums/sharepoint/en-US/d52e2e1b-5938-43c0-9708-8d9d710880ae/custom-web-part-properties-in-sharepoint-2010-visual-web-partsdynamic-dropdown

http://dev-tips.blogspot.in/2007/06/custom-property-of-webpart-dynamic.html

0

Use this code to populate the dropdown list.

    SPWeb web = SPContext.Current.Web;
    foreach(SPList list in web.Lists)
    {
    dropdownList.Items.Add(list.Title)
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.