Getting C1 CMS Data

Get CMS Data in User Control functions

You can get data from CMS Data types by using the DataConnection's Get method (C1 CMS API).

In the example below, since CMS Pages are essentially data types (Composite.Data.Types.IPage), you can get them as C1 CMS data.

You can use a Repeater to list the data items.

.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GetPagesData.ascx.cs" Inherits="C1Function" %>

<asp:Repeater ID="C1Pages" runat="server">
    <ItemTemplate>
        <%# Eval("Title") %><br />
    </ItemTemplate>
</asp:Repeater>
 

Download the sample

.ascx.cs

using System;
using Composite.Functions;
using Composite.Data;
using Composite.Data.Types;

public partial class C1Function : Composite.AspNet.UserControlFunction
{
    public override string FunctionDescription
    {
        get 
        { 
            return "A demo function that gets C1 pages as data and lists their titles."; 
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        using (var connection = new DataConnection())
        {
            C1Pages.DataSource = connection.Get<IPage>();
            C1Pages.DataBind();
        }
    }
}
 
Download the sample

Replace IPage in the example with your data type for your case.