Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In a Webpart I want to set some customs properties. I have this code

[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("myName"), WebDescription("myDescription"), Category("myCategory")]
        public string MyProperty
        {
            get { return _myProperty; }
            set { _myProperty= value; }
        }

that it renders a input text in the config menu. Since here its all ok.

But now I need to render another property as a select with 2 o 3 options. How can I do it?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can declare an enum in your webpart and expose that as property. An enum will be rendered as a dropdown in the properties toolpane. If you need more complicated behavior you need to create a custom ToolPart.

//create enum
public enum MyColorEnum {
  Red = 0,
  Blue,
  Yellow
};

protected MyColorEnum _color;

[Personalizable(PersonalizationScope.User), WebBrowsable,
 WebDisplayName("Color"), WebDescription("Color")]
public MyColorEnum Color
{
  get { return _color; }
  set { _color = value; }
}
share|improve this answer
add comment

You have to create a custom ToolPart for your WebPart. Here is an example: http://sharepoint-insight.blogspot.com/2008/10/sharepoint-creating-web-part-with.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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