Create a custom drop-down

Topics: Developer Forum
Aug 25, 2008 at 9:14 AM
Hi, I want to create a drop-down part, whose items will be editable.
Any idea how should I accomplish this?
How can I find and parse the content of an EditableTextArea before displaying the part?

Aug 25, 2008 at 12:44 PM

could you explain what you mean by "drop-down part"?
Do you want to have a custom drop-down element with editable items?
Or should we read that you want a drop-down which contains custom data (like parts) and after selecting a item you want the contents of an EditableTextArea to be filled with related data?

Aug 25, 2008 at 2:28 PM
Sorry for not being too clear, I want a drop-down with editable items, when a part is added to a drop zone and the edit mode is displayed, I need some way of getting the text entered in a text area and translate it into a list of items...

Aug 25, 2008 at 3:05 PM
sorry, but I still do not get it...could you elaborate a bit more?
Perhaps some examples?
Aug 25, 2008 at 3:22 PM
There is no such control in ASP.NET (by default).

However, there are plenty (open source and commercial) that you can use, for example:
Aug 25, 2008 at 3:23 PM
So, we have a CMS part that is displayed like a label and beneath  it a  drop down  list.
I  want the items from the drop down to be editable when the user places the part on the page.
For example, the user introduces the items separated by enter or comma in a text area and those items to appear as options in the drop down list.

Aug 25, 2008 at 3:33 PM
So, I figure that the dropdown is on the website and not in the edit-mode?
The end-user (visitor) must see a dropdown with items created in the edit-mode of N2?

You could use a EditableTextBox and  let the editor enter the values seperated by ; or something like that. Then add items to the textbox (.Items.Add) when showing it.
Use Split to parse the contents of the TextBox one by one.
Better options would be to use the tree (each items is a child?) or, even better, check out the FAQ structure in the templates example...

Aug 26, 2008 at 7:02 AM
Thanks for your help, I will give your suggestions a try today.

Oct 9, 2008 at 8:45 PM
EditableDropDown Part
Nov 29, 2008 at 1:53 PM
There is an error on the page, there is no source code for the UpdateEditor method, only UpdateItem twice...
Nov 29, 2008 at 8:06 PM
Thanks for noticing, I fixed the page.
Jan 9, 2009 at 5:51 PM
This page needs updating again

The required overrideable methods are now:

        public abstract void UpdateEditor(ContentItem item, Control editor);

        // Returns:
        //     True if the item was changed (and needs to be saved).
        public abstract bool UpdateItem(ContentItem item, Control editor);

        protected abstract Control AddEditor(Control container);

here is my Peterblum date textbox attribute, please let me know if it can be improved.

using PeterBlum.DES;

public class EditablePeterBlumCalendarAttribute : N2.Details.AbstractEditableAttribute
    public override bool UpdateItem(N2.ContentItem item, Control editor)
        DateTextBox dateTextBox = (DateTextBox)editor;
        DateTime? dateTime = dateTextBox.DateNullable;
        item[this.Name] = dateTime;
        return true;

    public override void  UpdateEditor(N2.ContentItem item, Control editor)
        DateTextBox dateTextBox = (DateTextBox)editor;
        dateTextBox.DateNullable = item[this.Name] as DateTime?;

    protected override Control AddEditor(Control container)
        DateTextBox dateTextBox = new DateTextBox();
        return dateTextBox;