ListView Controls

ListView Controls

ListView Controls

  • A data-bound container control that produces a list of individual item objects
  • Used to create custom lists from Sitecore items or other data
  • Binds to objects that are returned from a data source and displays them
  • Displays data formatted by templates and styles that you define
  • Supports custom event handlers
  • Enables users to edit, insert, and delete data, and to sort and page data

ListView Paging

  • Is not an integral part of the ListView control
  • Is provided through the DataPager control
  • Add the DataPager control in the LayoutTemplate of the ListView control


  • A web user control cannot be accessed directly; it must be hosted in a web form (aspx page)
  • The following issues can occur when attempting to use ASP.NET controls to display Content Tree items:
    • Viewstate issues
    • Paging issues
  • The solution is to add an entry for the ListView to the <typesThatShouldNotBeExpanded> section of the web.config file

ListView ASCX File Markup

<div style="font-weight: bold; width: 100%; clear: both">     <asp:Label ID="Label1" runat="server" /> </div> <div style="font-size: x-small; width: 100%; clear: both">     <asp:Label ID="Label2" runat="server" />       <asp:ListView ID="ListView1" runat="server" GroupItemCount="1">         <LayoutTemplate>           <table cellpadding="2" width="300px" id="tblListView" runat="server">             <tr id="Tr1" runat="server">               <th id="Th1" runat="server">Developers Topics</th>             </tr>             <tr runat="server" id="itemPlaceholder" />           </table>           <asp:DataPager ID="DataPager1" runat="server" PageSize="4" PagedControlID="ListView1" OnPreRender="DataPager1_PreRender">             <Fields>               <asp:NumericPagerField  ButtonType="Button" ButtonCount="10" NextPageText="more.." />             </Fields>           </asp:DataPager>         </LayoutTemplate>         <ItemTemplate>           <tr id="Tr2" style="background-color:Gray;" runat="server">             <td> <%# Container.DataItem %> <br /> </td>           </tr>         </ItemTemplate>         <AlternatingItemTemplate>           <tr id="Tr3" style="background-color:Silver;" runat="server">           <td> <%# Container.DataItem %> <br /> </td>           </tr>         </AlternatingItemTemplate> </asp:ListView> </div>

Listview C# User Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

Sitecore.Data.Items.Item ancestor = item.Parent.Parent.Parent;
if (item == null) return;

Label1.Text = "C# User Control Real-time Output";
string displayName = Sitecore.StringUtil.GetString(ancestor.DisplayName, ancestor.Name);
//using &#58; for colon and &#160; for space
Label2.Text = ("<p>Item&#58;&#160;" + "<b>" + displayName + "</b></p>");

Sitecore.Collections.ChildList children = ancestor.GetChildren();
foreach (Sitecore.Data.Items.Item child in children)
ListView1.DataSource = itemArray;

if (IsPostBack)

protected void DataPager1_PreRender(object sender, System.EventArgs e)
            ListView1.DataSource = itemArray;


Listview Configuration Settings

  • <configuration>
    • <sitecore>
      • <rendering>
        • <typesThatShouldNotBeExpanded>
          • <type>System.Web.UI.WebControls.Repeater</type>                
          • <type>System.Web.UI.WebControls.GridView</type>                
          • <type>System.Web.UI.WebControls.DataList</type>                
          • <type>System.Web.UI.WebControls.ListView</type>