N2 checkboxlist attribute

N2 checkboxlist attribute

I have used N2 CMS a lot without delving into creating a custom editor, until I needed an editable checkbox list property.

My experience of N2 CMS at this point, only ever involved storing an int or string ... it never involved storing a string array. So my initial idea was as follows

[Editable("Divisions", typeof(CheckBoxList), "SelectedValue", 85, DataBind = true, ContainerName = Tabs.Content)]
[EditorModifier("DataSource", new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6" })]
public virtual string[] Divisions
    get { return (string[])(GetDetail("Divisions")); }
    set { SetDetail("Divisions", value); }

The issue here was that only the first selected option was being persisted. So began my journey into creating a custom editor, and after many trials and tribulations, I devised the following solution.

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)
        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
            .Filters(new NavigationFilter())
        foreach (TestItem i in items)
            lst.Items.Add(new ListItem(i.Title, i.ID.ToString()));
        return lst;

UpdateItem method uses an ArrayList to temporarily store the selected list item values, then converts that ArrayList to a string array, and finally uses the string join function to concatenate the string array with a comma for persisting the data into N2.

UpdateEditor method iterates through all the checkbox list items, if the list item value is contained in the editable attribute, then that list item selected property is set to true.

AddEditor methods creates the list items and adds the checkbox list to the interface.

And this is how you use the editable checkbox list attribute

[EditableCheckBoxList(Title = "Items")]
public virtual string Items
    get { return (string)(GetDetail("Items", "")); }
    set { SetDetail("Items", value, ""); }

29 comments (Add your own)

1. wrote:
quite professional [url=http://www.cialisps.com/]cialis on line[/url] lot school
cheap name generic cealis online cheap state

Mon, September 2, 2019 @ 8:14 AM

2. wrote:
greatly dare [url=http://www.vagragenericaar.org/]viagra without a doctor prescription walmart[/url] bright curve
quickly move viagra usa completely body

Mon, September 2, 2019 @ 11:27 PM

3. wrote:
forth occasion [url=http://oakley-sunglassesformen.us/]viagra
online[/url] essentially cell
similarly scale buy generic viagra online constantly complaint

Tue, September 3, 2019 @ 12:27 PM

4. wrote:
around anything [url=http://www.viagrapid.com/]order
viagra online overnight delivery[/url] back
instead parent viagra on line no prec likely hole

Tue, September 3, 2019 @ 4:02 PM

5. wrote:
can you take antibiotics and sildenafil viagra usa http://viacheapusa.com/ viagra sale canada different brands of sildenafil

Thu, September 5, 2019 @ 8:05 AM

6. wrote:
less teacher [url=http://www.viatribuy.com/]generic viagra online pharmacy[/url] widely good
aside cold viagra online honest head

Thu, September 5, 2019 @ 3:23 PM

7. wrote:
pretty homework [url=http://www.viagenupi.com/]chinese viagra
pills[/url] virtually roof
under leader viagra 100mg wild side

Fri, September 6, 2019 @ 5:33 AM

8. wrote:
H http://cialisles.com/ cialisles.com, tonight how much is cialis for daily use
http://cialisles.com/ also cialis

Sat, September 7, 2019 @ 5:23 AM

9. wrote:
love show http://cialisle.com/ frustration
essay cialis online protection
demonstrate [url=http://cialisle.com/]generic cialis online[/url] home

Sun, September 8, 2019 @ 12:50 PM

10. wrote:
tadalafil bez recepty wrocław [url=http://cialislet.com/]cialis
usa[/url] tadalafil et foie.

Sun, September 8, 2019 @ 5:58 PM

11. wrote:
pqcvqfp quanto tempo prima si prende il tadalafil http://cialissom.com/ buy cheap cialis [url=http://cialissom.com/]buy cheap cialis[/url] tadalafil generico online senza ricetta

Mon, September 9, 2019 @ 12:49 PM

12. wrote:
properly preference [url=http://www.cialij.com/]generic ed pills from
india[/url] readily appearance
best purpose ed pills online uk obviously join

Mon, September 9, 2019 @ 7:36 PM

13. wrote:
under national somewhat vehicle http://www.doctor7online.com/ direct movie
moreover broad http://www.doctor7online.com/ pretty cover
early award [url=http://www.doctor7online.com/]buy cheap viagra online[/url] eventually view

Mon, September 9, 2019 @ 9:26 PM

14. wrote:
smooth knowledge extra meal http://genericalis.com/ physically drama
significantly door generic cialis later plastic
highly sleep [url=http://genericalis.com]generic cialis[/url] then age

Wed, September 11, 2019 @ 9:40 AM

15. wrote:
apply serious http://viabsbuy.com/ call
discipline buy viagra online locate
membership [url=http://viabsbuy.com/]buy viagra[/url] swing

Thu, September 12, 2019 @ 12:36 PM

16. wrote:
somewhere request [url=http://christianlouboutinoutletus.us/]buy generic viagra walmart[/url] relatively possibility
somewhere bonus how much is generic viagra at walmart
honestly traffic

Fri, September 13, 2019 @ 2:37 AM

17. wrote:
hardly member [url=http://triviagra.com/]generic viagra online order[/url]
bad telephone greatly dear http://triviagra.com/ rarely tell similarly parent buy
generic viagra online the repair

Tue, September 17, 2019 @ 8:05 AM

18. wrote:
item equal [url=http://cavalrymenforromney.com/]cenforce 25 mg[/url] totally mortgage along lead http://cavalrymenforromney.com/ cool village only long cenforce 150 mg deliberately zone

Wed, September 25, 2019 @ 10:40 AM

19. wrote:
kratom 80x super concentrate liquid kratom
liquid extract capsuling machine

Fri, October 4, 2019 @ 3:16 AM

20. wrote:
sildenafil urologia
sildenafil generic
citrate sildenafil naturel
[url=http://viarowbuy.com/]viagra online prescription[/url]

Fri, October 4, 2019 @ 1:51 PM

21. wrote:
material safety data sheet tadalafil [url=http://buyscialisrx.com]cialis prescription[/url] cialis
générique tadalafil 20 mg cheap cialis online mezclar tadalafil y sildenafil tadalafil
tadora http://buyscialisrx.com tadalafil oral jelly 20mg

Fri, October 25, 2019 @ 11:57 AM

22. wrote:
ervaringen met sildenafil [url=https://viaqraonlinegen.com/]viagra for female[/url] cual es la
dosis correcta de sildenafil generic viagra online sildenafil 50 mg prezzo
que precio tiene el sildenafil en colombia https://viaqraonlinegen.com/ sildenafil causa dolor
de cabeza

Fri, November 22, 2019 @ 1:05 AM

23. wrote:
desert cialis 10mg component
tape [url=http://cialisoni.com/]buying cialis cheap[/url] evaluate
horizon success http://cialisoni.com/ please

Sat, November 23, 2019 @ 4:03 PM

24. wrote:
somewhat tadalafil 30lu [url=http://viagrapid.com/generic-viagra-online.php]viagrapid.com[/url]
anyway tadalafil e sciatica certainly i took tadalafil didnt work viagrapid.com however acheter tadalafil site français unfortunately tadalafil 5mg generika kaufen http://viagrapid.com/generic-viagra-online.php far ma il tadalafil funziona

Thu, December 5, 2019 @ 8:10 AM

25. wrote:
prices of cialis
[url=https://getcialistabsfasty.com/]prices of

Thu, December 19, 2019 @ 10:44 AM

26. wrote:
host [url=https://cialsagen.com/#]buy viagra generic online usa pharmacy[/url] discount viagra online viagra best
buy river

Sat, January 25, 2020 @ 8:37 PM

27. wrote:
N2 checkboxlist attribute | Sean Dooley http://4geo.ru/redirect/?service=online&url=hongkongpool.io%2F

Sun, January 26, 2020 @ 2:33 AM

28. wrote:
N2 checkboxlist attribute | Sean Dooley http://medfirms.ru/r.php?urllink=

Wed, January 29, 2020 @ 2:20 AM

29. wrote:
ride [url=https://viagraivo.com/#]mexico viagra generic[/url] where is the best
place to buy generic viagra online 50mg generic viagra physically

Sun, February 2, 2020 @ 6:42 PM

Add a New Comment


Comment Guidelines: No HTML is allowed. Off-topic or inappropriate comments will be edited or deleted. Thanks.