Query items using a path

Topics: Developer Forum
Oct 20, 2008 at 4:37 PM

Is it possible to query items using the path?
Something like:

System.Collections.Generic.IList<N2.ContentItem> items = N2.Find.Items.Where.Detail("Path").Eq<string>("/Root/MyItems").Select();

Oct 20, 2008 at 7:10 PM
Probably not the way you're hoping. You want to query all items in a certain branch, right?

The path property on the content item is dynamically generated based on the parent trail. A possible option would be attaching to the itemsaving event and update a detail on the item and all it's children. Something like:

Persister.ItemSaving +=
    e.AffectedItem["MyPath"] = e.AffectedItem.Path;
Oct 21, 2008 at 8:23 AM

Yes, you're right. I want to query all items (xpath style) in a certain branch.
I had an idea of a new listcontrol, that would list children from a path.
Something like this:

[DisplayList(”Course type”, 100, ContainerName = Tabs.Content, Source = ”Root/MyItems”, SelectedValue = ”SelectedValue”)]
public virtual int? CourseTypeID
     get { return this.GetDetail("CourseTypeID") as int?; }
     set { this.SetDetail("CourseTypeID", value); }

Perhaps N2 already can do this?

Oct 21, 2008 at 6:14 PM
You could probably devise a custom editable to do that by traversing the content item structure. I've thought about adding xpath support for ages but never really needed it.
Oct 23, 2008 at 4:54 PM

Thanks for the help Christian! I was actually quite easy to create a custom EditableControl.
I created a EditableListControl which accepts a named path and the type of webcontrol to use for rendering.

[Hojgaard.Details.EditableListControl("Lokation", 150, typeof(System.Web.UI.WebControls.RadioButtonList), SourcePath = "System/Legestue typer", ContainerName = Tabs.Content)]
public virtual int? LocationID
    get { return this.GetDetail<int?>("LocationID", null); }
    set { this.SetDetail<int?>("LocationID", value); }

Next step is to create my own DatePicker control. I'm having some problems with the N2 DatePicker.

When selecting a date, using the DatePicker, the date is added like ”2008-10-23”.
When I edit the item, the date is shown in the following format ”23-10-2008” which is okay by me.
The date is still correct... but it confuses the date popup control.
If I want to select a new date, the popup calendar thinks the prevous selected date is the March 30, 1929.

I guess the DatePicker is confused because I use the culture "da-DK" (danish) :o)

Oct 23, 2008 at 9:09 PM
Right, that date picker isn't really internationalized. Sorry.

If you want you could use jquery ui's datepicker and contribute your changes: http://ui.jquery.com/repository/latest/demos/functional/#ui.datepicker