Answered by:
Web Part Properties as Custom Dropdown menu

Question
-
HI,
i have this dropdown and i want to use ti in the Webpart properties is it possible?
using (SPSite oSite = new SPSite(this.strSiteURL)) { using (SPWeb oWeb = oSite.OpenWeb()) { foreach (SPList list in oWeb.Lists) { ListNameDD.Items.Add(list.ToString()); string SelectedList = ListNameDD.SelectedItem.ToString(); strListName = SelectedList; } oWeb.Dispose();
Thank youFriday, November 29, 2013 12:45 PM
Answers
-
you can create a custom editor part the custom editor part will inherit from editor part
public class CustomEditorPart : EditorPart
you need to override 3 methods
CreateChildControls
in the above method you will create your custom controls
ApplyChanges
will save changes from your custom controls to webpart properties
SyncChanges
load the webpart properties to the custom controls
in your webpart place the below code to utilize the custom editor part
public override EditorPartCollection CreateEditorParts() { List<EditorPart> editors = new List<EditorPart>(); editors.Add(new CustomEditorPart { ID = this.ID + "_editPart1", Title = "your custom title" }); return new EditorPartCollection(editors); } public override object WebBrowsableObject { get { return this; } }
Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010
- Marked as answer by gohberto Tuesday, December 3, 2013 1:16 PM
Saturday, November 30, 2013 11:15 PM
All replies
-
The easiest way to add a dropdown to the web part properties is to define it as an enumeration. That will automatically be converted to a dropdown in the web part properties panel. This site has an example of how to do an enum.
http://www.sharepointblog.in/2013/07/creating-custom-web-part-properties-in.html
I'm not sure that will work in your case since your list will probably change over time. To add a dropdown property that can be populated at run time you would need to create a custom tool pane for the webpart. Here's an article on creating a custom editor panel.
http://msdn.microsoft.com/en-us/library/hh228018(v=office.14).aspx
Paul Stork SharePoint Server MVP
Principal Architect: Blue Chip Consulting Group
Blog: http://dontpapanic.com/blog
Twitter: Follow @pstork
Please remember to mark your question as "answered" if this solves your problem.- Proposed as answer by Hemendra Agrawal Tuesday, December 3, 2013 9:41 AM
Friday, November 29, 2013 12:51 PM -
you can create a custom editor part the custom editor part will inherit from editor part
public class CustomEditorPart : EditorPart
you need to override 3 methods
CreateChildControls
in the above method you will create your custom controls
ApplyChanges
will save changes from your custom controls to webpart properties
SyncChanges
load the webpart properties to the custom controls
in your webpart place the below code to utilize the custom editor part
public override EditorPartCollection CreateEditorParts() { List<EditorPart> editors = new List<EditorPart>(); editors.Add(new CustomEditorPart { ID = this.ID + "_editPart1", Title = "your custom title" }); return new EditorPartCollection(editors); } public override object WebBrowsableObject { get { return this; } }
Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010
- Marked as answer by gohberto Tuesday, December 3, 2013 1:16 PM
Saturday, November 30, 2013 11:15 PM