SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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

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

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.