Is it possible in Sitecore 7.5 to bind all the names in a Name Value Lookup to a datasource?

For example the name will be represented as a dropdown list.

This is not possible out of the box, you will need to create a custom field in order to achieve this.

I've previously blogged about a custom Name Value Lookup field, which allows the key portion of the list to be datasource driven and only selectable from a dropdown list.

Custom Name Value field

All the code is available in this Github Gist, but essentially:

  • Create a new custom field that inherits from Sitecore.Shell.Applications.ContentEditor.NameLookupValue
  • Override the OnLoad method (inherited from base of above), and provide your own implementations of LoadValue() and BuildControl().
  • The original LoadValue() code has a regex validation in there which disallows dashes (i.e. not good for GUIDs)
  • The BuildControl() method calls through to generate the required markup of your control. In the case of this custom field, line 112 is where the call is made to get the collection of items based on the datasource value and then build the dropdown list. Modify the logic and markup as required.

There is also a more recent post that builds on the above and allows use of Datasource queries to resolve the list, if that is a requirement.

Not really, no. But I've used a custom field type many times that sort of does what you ask.

It's called Unbound Droplist.

It basically allows you to set a pipe delimited string as values in a droplist. Like red|white|orange. It's not quite what you ask, but I would need to know more about what you're trying to accomplish to narrow an answer down further.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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