SenseNetDataSource

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned

Overview

SenseNetDataSource is a user control based on the standard .Net DataSourceControl. Portal builders can use it to populate any list control (data-bound control) that can work with a data source. SenseNetDataSource has a simple API for collecting content using a query and presenting it to the list control.

Details

SenseNetDataSource control provides a content collection for data-bound controls. This means that it does not generate any html itself, it only collects the content and prepares them for presenting. It needs to be used in pair with a data-bound control like an ASP.NET ListView or DropDown control.

A data-bound control can make use of the content provided by the SenseNetDataSource control by referencing its ID as the DataSourceID attribute.

<sn:SenseNetDataSource ID="SNDSControl" runat="server"  />
 
<asp:ListView ID="MyListView" runat="server" DataSourceID="SNDSControl"  >
...
</asp:ListView>

SenseNetDataSource can work with the current environment of the portal (for example using the current context or the current user or workspace). You can select a specific content by setting the ContentPath property as shown in the next section. In any of these cases the SenseNetDataSource control will provide content that are in the sub-tree of the selected content. If you want to work with content from anywhere in the repository you can do so by setting the Query property. Of course these two settings can work together, you can select a content and provide a filtering query at the same time.

Properties

Query

You can provide a query for the datasource. The control will return the result of the query.

<sn:SenseNetDataSource ID="SNDSControl" Query="+InFolder:/Root/YourContents +Type:HTMLContent" runat="server"  />

Settings

This property cannot be used from html but from source code. Developers can provide an object here that holds information about sorting the results and top/skip values. For more information see QuerySettings page.

ContentPath

You can provide a fix content for the datasource by setting the ContentPath property. If you provide only this information the returned content will be the children of the given content.

ContextInfoID

SenseNetDataSource can work with the current environment that the portal provides. This is achieved through a ContextInfo control that can provide the context information for the datasource control. You can set the Selector property of the ContextInfo control to the appropriate context and the datasource control will work with that content.

<sn:ContextInfo runat="server" Selector="CurrentContext" ID="myContext" />

You can set the Selector property to any of the following values:

  • CurrentContext (default, if Selector is not given)
  • CurrentUser
  • CurrentPage
  • CurrentSite
  • CurrentList
  • CurrentWorkspace


The UsePortletContext property of the ContextInfo control determines if the context of the current context-bound portlet should be used. In this case you do not need to give a Selector.

<sn:ContextInfo runat="server" UsePortletContext="true" ID="myContext" />

MemberName

You can list all the content that are referenced by another content using the MemberName property. For example if you want to list the related content for an article, you provide the article itself with the ContentPath or the ContextInfoID property and set the MemberName property to RelatedArticles. The following example can be placed into a content view that is presented on a smart page for an article.

<sn:ContextInfo runat="server" Selector="CurrentContext" UsePortletContext="true" ID="myContext" />
<sn:SenseNetDataSource ID="SNDSControl" ContextInfoID="myContext" MemberName="RelatedArticles" runat="server"  />
...

FlattenResults

You can set whether only the children under the selected content should be displayed or all the content in the sub-tree. This can be done with the FlattenResults property. The default value is false but if you set it to true, all the content under the selected content will be displayed.

<sn:SenseNetDataSource ID="SNDSControl" ContentPath="/Root/YourContents" FlattenResults="true" runat="server"  />

FieldNames

DefaultOrdering

Example/Tutorials

List referenced content

You can get the members of a group by placing these two controls to a content view or any ascx file:

<sn:SenseNetDataSource ID="SNDSMembers" ContentPath="/Root/IMS/BuiltIn/Portal/Editors" MemberName="Members" runat="server"  />
 
<asp:ListView ID="MemberListView" runat="server" EnableViewState="false" DataSourceID="SNDSMembers"  >
    <LayoutTemplate>      
        <table >
          <tr>  
              <th>Username</th>    
              <th>Full name</th>	   
          </tr>
          <tr runat="server" id="itemPlaceHolder" />
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>      		
          <td><%# Eval("Name") %></td>
          <td><%# Eval("FullName") %></td>
        </tr>
    </ItemTemplate>
    <EmptyDataTemplate>
    </EmptyDataTemplate>
</asp:ListView>

Related links

References