When it comes to create custom web part with a dropdown as custom property, it isn't immediately obvious how to include a drop down list as a custom property on a web part. To accomplish this we simply use an enum. See below the example enum used as menu items, first declare the enum and then the property and it works
#region Custom Properties
public enum Tab
{
SELECT = 0,
Partha = 1,
Abhijit = 2,
India = 3,
Test = 4,
Sanjay = 5,
}
[System.Web.UI.WebControls.WebParts.WebBrowsable(true),
System.Web.UI.WebControls.WebParts.WebDisplayName("Provide the Select Menu Item"),
System.Web.UI.WebControls.WebParts.WebDescription(""),
System.Web.UI.WebControls.WebParts.Personalizable(),
System.ComponentModel.Category("Partha Library Properties"),
System.ComponentModel.DefaultValue(""),]
public Tab tabName
{
get;
set;
}
If you have a more elegant solution – please post a comment… I’ll be happy to hear.
...HaPpY CoDiNg
Partha (Aurum)
Ref:
http://msdn.microsoft.com/en-us/library/dd584174(v=office.11).aspx
Hi How can I add event to this dropdown list
ReplyDeletehi.
ReplyDeleteHow can I can do when I want to pass all Groups Name in a site to Enum