Section 9.6. Repeater Control

9.6. Repeater Control

There is one other major player in the game of displaying data: the Repeater Control. The most frequently asked question is which control to use at any given time. Table 9-6 summarizes the differences.

Table 9-6. Comparing Repeater DataList and GridView controls

Feature

Repeater

DataList

GridView

Table layout

No

No

Yes

Flow layout

Yes

Yes

No

Column layout

No

Yes

No

Style properties

No

Yes

Yes

Templates

Yes

Yes

Columns/optional

Select/ Edit/Delete

No

Yes

Yes

Sort

No

No

Yes

Paging

No

No

Yes


The Repeater provides a subset of the DataList and is typically used only when you do not want a column layout.

The Repeater control is "lookless"--that is, there is no predetermined look for the control; you determine how it will appear by adding templates. The potential templates are shown in Table 9-7.

Table 9-7. Repeater Control templates

Template

Description

AlternatingItemTemplate

Used as you would the item template; however, the alternating item is rendered for every other row in the control.

FooterTemplate

Elements to render after all items and other templates have been rendered.

HeaderTemplate

Elements to render before any other templates are rendered.

ItemTemplate

Elements rendered once for each row in the data source.

SeparatorTemplate

Elements to render between each row in the data source.


To get started, add a page to WebNorthWindDataControls named RepeaterDemo.aspx . Drag a Repeater control onto the page from the Data tab in the toolbox. The smart tag opens and asks you to choose (or create) a new data source. This process is identical to the one you did for DataLists ( name this datasource RepeaterCustomerDataSource ).

The Repeater does not have a default appearance; you control it entirely with the templates, which are, essentially , snippets of HTML and .NET Server Controls listed within Template elements:

 <asp:Repeater id="Repeater1" runat="server" DataSource="<%# RepeaterCustomerDataSource %>">    <ItemTemplate>       <asp:Label id=Label1 runat="server"          Customer='<%# DataBinder.Eval(Container, "DataItem.Name")%>'>       </asp:Label>    </ItemTemplate>    <SeparatorTemplate>, </SeparatorTemplate> </asp:Repeater> 



Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net