Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After spending a few hours checking out n2cms custom editors, below is my solution</p> <pre><code>public class EditableCheckBoxListAttribute : AbstractEditableAttribute { public override void UpdateEditor(N2.ContentItem item, Control editor) { CheckBoxList lst = editor as CheckBoxList; if (lst != null) { foreach(ListItem li in lst.Items) { if (item[this.Name].ToString().Contains(li.Value)) { li.Selected = true; } } } } public override bool UpdateItem(N2.ContentItem item, Control editor) { CheckBoxList lst = editor as CheckBoxList; ArrayList items = new ArrayList(); foreach (ListItem li in lst.Items) { if (li.Selected) { items.Add(li.Value); } } string[] itemID = (string[])items.ToArray(typeof(string)); item[this.Name] = String.Join(",",itemID); return true; } protected override Control AddEditor(Control container) { CheckBoxList lst = new CheckBoxList(); var items = N2.Find.Items .Where.Type.Eq(typeof(TestItem)) .Filters(new NavigationFilter()) .Select&lt;TestItem&gt;(); foreach (TestItem i in items) { lst.Items.Add(new ListItem(i.Title, i.ID.ToString())); } container.Controls.Add(lst); return lst; } } </code></pre> <p>And this is how you use it</p> <pre><code>[EditableCheckBoxList(Title = "Items")] public virtual string Items { get { return (string)(GetDetail("Items", "")); } set { SetDetail("Items", value, ""); } } </code></pre> <p>As an added bonus, here is a radio button list editable attribute</p> <pre><code>public class EditableRadioListAttribute : AbstractEditableAttribute { public override void UpdateEditor(N2.ContentItem item, Control editor) { RadioButtonList rbl = editor as RadioButtonList; if (rbl != null) { rbl.SelectedValue = item[this.Name].ToString(); if (rbl.Items.FindByValue(item[this.Name].ToString()) != null) { rbl.Items.FindByValue(item[this.Name].ToString()).Selected = true; } } } public override bool UpdateItem(N2.ContentItem item, Control editor) { RadioButtonList rbl = editor as RadioButtonList; string itemID = rbl.SelectedValue; item[this.Name] = itemID; return true; } protected override Control AddEditor(Control container) { RadioButtonList rbl = new RadioButtonList(); var items = N2.Find.Items .Where.Type.Eq(typeof(TestItem)) .Filters(new NavigationFilter()) .Select&lt;TestItem&gt;(); foreach (TestItem i in items) { rbl.Items.Add(new ListItem(i.Title, i.ID.ToString())); } container.Controls.Add(rbl); return rbl; } } </code></pre> <p>And this is how you use it</p> <pre><code>[EditableRadioListAttribute(Title = "Item")] public virtual string Item { get { return (string)(GetDetail("Item", "")); } set { SetDetail("Item", value, ""); } } </code></pre> <p>Hope this helps</p> <p>Sean</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload