Sitefinity CMS

Add a List Control to a User Control Send comments on this topic.
How-to > Modules > Built-in Modules > Lists > Add a List Control to a User Control

Glossary Item Box

This topic demonstrates how to create a user control and implement a Lists public control in it.

 

A user control could wrap an existing List control, and implement the custom logic. There are two important aspects to cover - the interface implementation, and the web editor. The user control should implement the IListDisplay interface. Also, the ListsIds property should have an appropriate WebEditor attribute. Following is an exemplary implementation of such a user control:

ListsControl.ascx Copy Code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListsControl.ascx.cs" Inherits="UserControls_ListsControl" %>
<
%@ Register Assembly="Telerik.Lists" Namespace="Telerik.Lists.WebControls" TagPrefix="sfLists" %>

<h2>My lists:</h2>
<
div>
 
<sfLists:ListDisplay ID="ListDisplay1" runat="server"></sfLists:ListDisplay>
</
div>

 

ListsControl.ascx.cs Copy Code
using System.ComponentModel;
using Telerik.Lists;
using Telerik.Cms.Web.UI;

public partial class UserControls_ListsControl : System.Web.UI.UserControl, IListDisplay
{
 
private string providerName;

 [Category(
"Data")]
 
public string ProviderName
 {
   get
   {
     
if (String.IsNullOrEmpty(this.providerName))
       
this.providerName = ListManager.DefaultProviderName;
     
return this.providerName;
   }
   set
   {
     
this.providerName = value;
   }
 }

 
protected void Page_Load(object sender, EventArgs e)
 {
 }
    
 #region IListDisplay Members

 [Category(
"Data")]
 [TypeConverter(
"Telerik.Lists.WebControls.ListsIdsConverter, Telerik.Lists")]
 [WebEditor(
"Telerik.Lists.WebControls.ListSelector, Telerik.Lists")]
 
public Guid[] ListsIds
 {
   get
   {
     
return this.ListDisplay1.ListsIds;
   }
   set
   {
     
this.ListDisplay1.ListsIds = value;
   }
 }
 #endregion
}

 

This is the line that should be added to the <toolboxControls> tag in the web.config file so that the user control is available in the Toolbox in the Admin part of Sitefinity:

web.config Copy Code
<add name="ListsControl" section="Lists" url="~/Sitefinity/UserControls/ListsControl.ascx" />