Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Created May 10, 2018 00:17
Show Gist options
  • Save fluxdigital/2f307d3bac3ab3d05a9d271d4d9f77b0 to your computer and use it in GitHub Desktop.
Save fluxdigital/2f307d3bac3ab3d05a9d271d4d9f77b0 to your computer and use it in GitHub Desktop.
An example Sitecore Multilist with an external datasource
namespace FluxDigital.Sitecore.Extensions.Fields
{
public class CryptoMultilist : BaseExternalMultiList
{
private List<CryptoCoin> _coinList;
protected override void InitRendering()
{
CryptoService cryptoService = new CryptoService();
_coinList = cryptoService.CointList();
}
protected override IEnumerable<KeyValuePair<string, string>> GetNonSelectedItems()
{
var nonSelectedGroups = new List<KeyValuePair<string, string>>();
_coinList.ForEach(coin => nonSelectedGroups.Add(new KeyValuePair<string, string>(coin.Id, coin.CoinName)));
return nonSelectedGroups;
}
protected override IEnumerable<KeyValuePair<string, string>> GetSelectedItems()
{
var selectedCoinIds = Value.Split('|');
var selectedCoins = new List<KeyValuePair<string, string>>();
foreach (var selectedGroupId in selectedCoinIds)
{
var coin = _coinList.FirstOrDefault(g => g.Id == selectedGroupId);
if (coin != null) selectedCoins.Add(new KeyValuePair<string, string>(coin.Id, coin.CoinName));
}
return selectedCoins;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment