1

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?

2 Answers 2

4

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; }
}
0

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

Your Answer

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

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