2

I'm programming a Web Part in Visual Studio 2010 with SharePoint 2010. It will post content that users choose from the configurable part when you click on "edit web part". I want add a drop down list in the configurable part that will show titles from a list. Based on their choice it will display content from that list from another filed associated with that title.

I already know how to let users enter custom content in the configuration part and let it show up in the web part. I'm really interested from the point of creating that drop down list.

Thanks

2 Answers 2

1

I believe you have a property of type string which represents the title from a list but SharePoint would render a text box instead of a dropdown containing list of titles.

SharePoint by default renders textbox for Web Part property of type string but that behavior can be modified by creating and associating a custom editor part for that property. The links below should help you;

http://msdn.microsoft.com/en-us/library/hh228018.aspx

http://code.msdn.microsoft.com/SharePoint-2010-Creating-a-b36c1597 (Code Sample)

http://www.wictorwilen.se/Post/Web-Part-Properties-part-2-Editor-Parts.aspx

1
  • Alternatively, you can use a ToolPart which is the SharePoint flavor of EditorPart.
    – Kit Menke
    Jan 9, 2012 at 15:42
1

This post will be great for you. In you case you should bind title of SPList as text and ID of SPList as value to drop down box. In web part property you should store ID of SPList and use this ID in your load data method.

I updated my answer. In this post the list items are binded to a drop down box. You can do your issue in the same approach, only bind your lists.

6
  • Not sure if he wants to use web part connections for this? As I understand it, he wants a custom dropdown list in the web part edit pane.
    – Kit Menke
    Jan 9, 2012 at 15:40
  • Sorry, I put incorrect url (((( this url is correct sharepointlessons.blogspot.com/2009/04/…
    – Alexander
    Jan 9, 2012 at 15:46
  • Can you edit your answer to include the correct link? Then, we can delete these comments. :)
    – Kit Menke
    Jan 9, 2012 at 15:51
  • Both of those links were helpful in creating a drop down. That's where I wanted to start. Now I need to put that drop down in the "configurable" side of the web part so that users can choose a title and the web part would display the body associated with that title. Thank you!
    – Felix
    Jan 9, 2012 at 19:01
  • Final user experience would be: Edit Web Part -> Select "Title" from drop down in configuration -> Web Part Content shows the "Body" associated with the Title in that list.
    – Felix
    Jan 9, 2012 at 19:07

Your Answer

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

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