Sitecore data source from selected items in multilist

I have a page with a multilist

My Multilist

and I want to create a second multilist with the selected values of the previous list (and reflecting the changes one the second multilist when the first one is modified).

How can I do that?

Upvotes: 2

Views: 2395

Answers (1)

Ahmed Okour
Ahmed Okour

Reputation: 2422

You will need to extend MultiListEx field and and add your dynamic source At DoRender event, your code should be like:

public class CustomMultiList : MultilistEx
{
  private void GenerateDynamicDatasource()
  {
    //write some code to get the selected IDs from the first multilist field
    //build a string with this query format :
    // string EncludedIDsQuery = "@@id == '[First Selected Guid]' or @@id == '[secondSelected Guid]'" and so on
    this.Source = "query:" + this.Source + "/*[" + EncludedIDsQuery+ "]";
  }

  protected override void DoRender(output)
  {
    this.GenerateDynamicDatasource();
    base.DoRender(output);
  }
}

Hope this helps!

Update

Keven has more reusable solution, and i think it will work for your case too: https://stackoverflow.com/a/25785363/2074649

Upvotes: 2

Related Questions