Free Consultation - Call 305 403 0899
Skip Navigation Links
Tutorial

ASP.NET Tutorial. How to use Repeater

Publish date: Tuesday October 28, 2008
Repeater_ASP.NET

In this article, I'll show you how to use Repeater in ASP.NET page.

Here is an example of Repeater:

I store the user in table "Client_NetroStar" in SQL Server.  There are five fields in the table:

  • ID
  • Login
  • FirstName
  • LastName
  • DateAdded

1. First Step - Insert the Repeater Control on page.

Repeater control allows you to create templates. For example you can use a template to customize the layout of the individual rows.

  • HeaderTemplate - template for elements that you want to render once before your ItemTemplate section.
  • ItemTemplate - template for elements that are rendered once per row of data.
  • AlternatingItemTemplate - template for elements that are rendered every other row of data. This allows you to alternate background colors, for example.
  • SeparatorTemplate - template for elements to render between each row, such as line breaks.
  • FooterTemplate - template for elements that you want to render once after your ItemTemplate section.

Here is the part of the “ClientNetroStar.aspx” page that contains Repeater:

The Repeater has an attribute ID= "rptList". It is used in  Code Behind (ClientNetroStar.aspx.cs) . Repeater uses the HeaderTemplate to insert <table> .  Then it uses the ItemTemplate to display a LinkButton control that has our data in it. I'll come back to this in the next  step.

The FooterTemplate is not necessary, but I put it in </table>.

2. Second Step - Get the Data to Repeater.

Here is the Page_Load event in the Code Behind file.

The first five lines open a database connection and retrieve the contents of the Client_NetroStar table. The last two lines bind our Repeater control to the DataReader.

We can use also MyGeneration to get data. Read more in Introduction to myGeneration and dOOdads.

Author: Mariusz Siergijewicz

Latest Tutorials Click here to see All Tutorials
Malgorzata Szabelska

Flash tutorial - How to send data to ASP.NET and read the answer

10-31-08 - by MaƂgorzata Szabelska

In this article I am going to present one possibility of sending data from flash site to ASP.NET and how from ASP.NET respond to FLASH.


Repeater_ASP.NET

ASP.NET Tutorial. How to use Repeater

10-28-08 - by Mariusz Siergijewicz

In this article, I'll show you how to use Repeater in ASP.NET page.


C# connection string

Connection String for MS SQL database

10-01-08 - by Pawel Matuszewski

This article shows how to connect from your web application to SQL Server database.