1

I'm kind of new to working with Web Parts so excuse me if I sound ignorant :)

I have this attribute for a web part where a user selects which college they belong to in the University, based on a dropdown. Currently the way it works is that it uses the enum names of the colleges as both the value and the display text for each dropdown item. What I would like, is to have text specified for the enums to be used for the display text. For example, one of the enum values is ArtsandSciences, but I would like it to be displayed as Arts and Sciences, spaces included. I've done some Googling but haven't been able to find any answers. What can I do?

Web part attribute

public enum Colleges
{
    ArtsandSciences,
    AppliedScienceandTechnology,
    Education,
    Nursing
};

private Colleges college = Colleges.ArtsandSciences;

[WebBrowsable(true),
    WebDescription("The college you belong to"),
    WebDisplayName("Your college"),
    Category("Digital Measures"),
    DefaultValue(Colleges.ArtsandSciences),
    Personalizable(PersonalizationScope.User)]
public Colleges College
{
    get { return college; }
    set { college = value; }
}
1

There is no such functionality out of the box for this.

You can check the following Workaround:

Display names in dropdown in webpart property

http://social.msdn.microsoft.com/Forums/en-US/015d3a48-4915-4177-afba-fbbc82b16a2b/enum-dropdown-list-as-a-custom-property-in-webpart?forum=sharepointdevelopmentprevious

  • Thanks for the links. Going along with the first one, I understand the first two code blocks in the answer, but the third one I'm not quite understanding. No where in my web part code do I specify a variable for the dropdown, ex. groupDropDown as they have. How would I really do that? – Chiggins Jun 16 '14 at 19:53
  • In second link it is mentioned that You need to create custom toolpart for this kind of scenrio and declare your owm drop dowm. You won,t get this is in webpart.cs file. – Aanchal Jun 17 '14 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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