{"id":73,"date":"2008-04-08T14:57:48","date_gmt":"2008-04-08T14:57:48","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=73"},"modified":"2008-04-08T15:03:58","modified_gmt":"2008-04-08T15:03:58","slug":"dropdown-option-lists-in-webpart-personalisation-menus","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/","title":{"rendered":"Dropdown option lists in webpart personalisation menus"},"content":{"rendered":"<p>I&#8217;ve been writing my own SharePoint webparts for a few months now and have been quite happy using personalisation options to provide a certain degree of control during runtime from the Edit Shared Webpart properties menu.<\/p>\n<p>All of these controls have either been using a text box entry or a tick box boolean, Until now that is. I realised that I needed to have some form of control over what was being entered by the admin. After all, whilst it&#8217;s always good to make sure that you validate any user input, it makes sense to restrict that input to selected options when possible.<\/p>\n<p>In my case, I want the admin to be able to choose between which teams to filter the inbound data on, this in turn was then fed into a CAML query to return the correct data for the webpart.<\/p>\n<p>After much reading of logs and blogs, I posted a quick question on the SUGUK forum and one of the readers, Paul Leigh suggested I look at using an Enum to provide the drop down.<\/p>\n<p>Quite intrigued, I brushed off my c# text book to remind me how to define an enum, and set off on the following code.<\/p>\n<p>First we define the enum within the webpart class boundary.<\/p>\n<p><code>Public enum resourceTypes : int<br \/>\n{<br \/>\nNR,<br \/>\nProjects,<br \/>\nWindows,<br \/>\nNetworks,<br \/>\nUnix,<\/p>\n<p><strong>snipped......<\/strong><\/p>\n<p>FirstAssist<br \/>\n};<br \/>\n<\/code><\/p>\n<p>Now we need to define the public and private members of the class, You don&#8217;t have to do this, but it&#8217;s best practice!<\/p>\n<p><code><br \/>\nprivate resourceTypes m_resourceFilter;<\/p>\n<p>[Personalizable(PersonalizationScope.Shared), Category(\"ESSOP\"), WebBrowsable(true), WebDisplayName(\"Select team to filter results by\")<br \/>\n, WebDescription(\"Use NR value when not required.\")]<br \/>\npublic resourceTypes resourceFilter<br \/>\n{<br \/>\nget {return m_resourceFilter;}<br \/>\nset {m_resourceFilter = value;}<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Thats really all there is to it, in my case, i evaluate the enumeration using the ToString method and push that into my query string.<\/p>\n<p><strong>NB: You can only use a single word in the enum, spaces aren&#8217;t allowed, so in order to get around some of my teams that have double barrelled names, I put a Select statement further down the code at the injection point into the CAML query&#8230;.<\/strong><\/p>\n<p><code><br \/>\n                        switch (m_resourceFilter.ToString())<br \/>\n                        {<br \/>\n                            case \"StorageBackup\":<br \/>\n                                resourceSelection = \"Storage & Backup\";<br \/>\n                                break;<\/p>\n<p>                            case \"TechOps\":<br \/>\n                                resourceSelection = \"Tech Ops\";<br \/>\n                                break;<\/p>\n<p>                            case \"FirstAssist\":<br \/>\n                                resourceSelection = \"First Assist\";<br \/>\n                                break;<\/p>\n<p>                            case \"BusinessAssurance\":<br \/>\n                                resourceSelection = \"Business Assurance\";<br \/>\n                                break;<\/p>\n<p>                            default:<br \/>\n                                resourceSelection = m_resourceFilter.ToString();<br \/>\n                                break;<br \/>\n                        }<br \/>\n<\/code><\/p>\n<p>Hopefully this might give you some pointers to solve a similar issue in your projects.<\/p>\n<p>Regards<\/p>\n<p>Reg.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been writing my own SharePoint webparts for a few months now and have been quite happy using personalisation options to provide a certain degree of control during runtime from the Edit Shared Webpart properties menu. All of these controls have either been using a text box entry or a tick box boolean, Until now &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[5,13,16,8,12],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dropdown option lists in webpart personalisation menus - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dropdown option lists in webpart personalisation menus - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve been writing my own SharePoint webparts for a few months now and have been quite happy using personalisation options to provide a certain degree of control during runtime from the Edit Shared Webpart properties menu. All of these controls have either been using a text box entry or a tick box boolean, Until now &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2008-04-08T14:57:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2008-04-08T15:03:58+00:00\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/\",\"url\":\"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/\",\"name\":\"Dropdown option lists in webpart personalisation menus - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"datePublished\":\"2008-04-08T14:57:48+00:00\",\"dateModified\":\"2008-04-08T15:03:58+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dropdown option lists in webpart personalisation menus - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/","og_locale":"en_US","og_type":"article","og_title":"Dropdown option lists in webpart personalisation menus - Blog of an overweight SharePoint addict","og_description":"I&#8217;ve been writing my own SharePoint webparts for a few months now and have been quite happy using personalisation options to provide a certain degree of control during runtime from the Edit Shared Webpart properties menu. All of these controls have either been using a text box entry or a tick box boolean, Until now &hellip; Continue reading","og_url":"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2008-04-08T14:57:48+00:00","article_modified_time":"2008-04-08T15:03:58+00:00","author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/","url":"https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/","name":"Dropdown option lists in webpart personalisation menus - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"datePublished":"2008-04-08T14:57:48+00:00","dateModified":"2008-04-08T15:03:58+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.myfatblog.co.uk\/index.php\/2008\/04\/dropdown-option-lists-in-webpart-personalisation-menus\/"]}]},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/73"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}