Kentico CMS 6.0 Controls

Getting started

Getting started

Previous topic Next topic Mail us feedback on this topic!  

Getting started

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

The following is a step-by-step tutorial that will show you how to display a list of laptops (CMS.Laptop documents) from the sample Corporate Site using the BasicRepeater control:

 

1. Create a new Web form somewhere in your website installation directory.

 

2. Switch to its Design tab, drag and drop a BasicRepeater control from the toolbox onto the form.

 

3. Switch to the Source tab and add the code marked by the BasicRepeater template comments between the <cms:BasicRepeater> tags. The overall code of the BasicRepeater control should look like this:

 

<cms:BasicRepeater ID="BasicRepeater1" runat="server">

 

<%-- BasicRepeater template --------------------------------------------------------- --%>

 

<itemtemplate>

  <h3>

      <%# Eval("LaptopName") %>

  </h3>

  <%# EcommerceFunctions.GetProductImage(Eval("SKUImagePath"), 200, Eval("LaptopName")) %>

</itemtemplate>

 

<%-- BasicRepeater template --------------------------------------------------------- --%>

 

</cms:BasicRepeater>

 

This defines the template used by the BasicRepeater to display items. The control dynamically replaces the <%#  ... %> tags with values of the currently displayed record. This is then repeated for every record in the data source.

 

4. Switch to the code behind of the page and add the following references to the beginning of the code:

 

[C#]

 

using System.Data;

 

using CMS.CMSHelper;

 

[VB.NET]

 

Imports System.Data

 

Imports CMS.CMSHelper

 

5. Now add the following code to the Page_Load method:

 

[C#]

 

DataSet ds = TreeHelper.SelectNodes("/%", false, "CMS.Laptop", "", "LaptopName", -1, true);

         

BasicRepeater1.DataSource = ds;

BasicRepeater1.DataBind();

 

[VB.NET]

 

Dim ds As DataSet = TreeHelper.SelectNodes("/%", False, "CMS.Laptop", "", "LaptopName", -1, True)

 

BasicRepeater1.DataSource = ds

BasicRepeater1.DataBind()

 

This retrieves all CMS.Laptop documents from the Kentico CMS database as a DataSet and assigns it as the data source of the BasicRepeater control.

 

6. Save the changes to the web form. Now right-click it in the Solution explorer and select View in Browser. The resulting page should display a list similar to the following:

 

controls_clip0033