Peter already wrote a few words about managing the custom fields of a Content List. The idea is that the collection of the custom fields can be presented as a list itself. This is possible because the topmost layer (e.g. a ListView) only needs a collection of Contents to work. The background of this - using Content fields with the standard Eval method and the way of presenting the custom fields as a list of Contents - will be a subject of another post (dynamic, in-memory content type creation, anybody?), right now I'm focusing on the presentation.
The solution is to create a custom view for the given ContentList. This view will show a list of the custom fields of the ContentList.
Creating a custom view
A custom view for a ContentList is a simple ASP.NET user control that contains the markup for the chosen data bound control. You can place this control (let's call it MyCustomView.ascx) to the Views folder of any ContentList, and you'll see it in the Views menu on the upper right corner. You can test the view by selecting it from the menu.
We placed two things into this user control:
- ListGrid: this is a common ASP.NET ListView with a few shiny scripts added
- SenseNetDataSource control
Using SenseNetDataSource with a ListGrid
Few weeks ago we introduced the SenseNetDataSource control, that makes building data-driven sites a lot easier. Like SQLDataSource, it gives all data bound controls access to pure data - in our case, contents in the Content Repository. One of its functions is to give access to a specific multireference member of a content (e.g.: a Product content may have a Suppliers member that refers to some Supplier contents).
This way we can get a collection of editable custom fields of a ContentList. In markup, it looks like:
<sn:SenseNetDataSource ID="ViewDatasource" MemberName="FieldSettingContents" runat="server" />
The MemberName can refer to any reference field of a content. In this case we created a "virtual" field called FieldSettingContents for the ContentList class that creates the contents from the custom fields. This is a _very_ special use case, in most cases you will use a simple reference field defined in the content type definition.
We can present the results with any data bound control: