Data FAQ

How can I define data available for selection in the widget?

I need a widget that will allow me to select the Title of a C1Page.

If I use DataIdMultiSelector and set C1Page as the datatype, it shows MenuTitle.

How can I define data available for selection?

Answer:

Because DataIdMultiSelector is bound to the label of the type, you need to use a different widget to achieve your goal:

  1. Create a file in the App_Code folder and add to it the following code that grabs IDs and titles of all C1 pages:
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using Composite.Data;
    
    namespace CompositeGetData
    {
        public class GetC1Pages
        {
            public static Dictionary<Guid, String> GetC1PagesInfo()
            {
                using (DataConnection connection = new DataConnection())
                {
                    var C1PagesInfo = from dataItem in connection.Get<Composite.Data.Types.IPage>()
                                      select new { dataItem.Id, dataItem.Title };
    
                    Dictionary<Guid, String> C1Pages = new Dictionary<Guid, String>();
                    foreach (var info in C1PagesInfo)
                        C1Pages.Add(info.Id, info.Title);
    
                    return C1Pages;
                }
            }
        }
    }
    Download the source
  2. Add a new C# function to C1 by registering it as CompositeGetData.GetC1Pages and selecting GetC1PagesInfo()
  3. In the datatype's string field, set the appropriate length.
  4. Switch to the Advanced tab and select a new widget: Composite.Widgets.String.Selector
  5. Set the Selector parameters to the following values:
  • Options: Execute complex function call => GetC1PagesInfo
  • Multiple selection: Simple value => Yes 
  • Compact Mode: Simple value => Yes