I'll tell you now that all of these methods of
viewing data is tedious and very complicated, but I'm sure that you can work
it out, your relatively smart humans.
The Repeater is a control that loops through
the data and displays it on templates that you create.
- ItemTemplate. This is the template
where it displays the main body of the data.
- AlternativeItemTemplate. You can have
an alternating style for every second item if you want.
- HeaderTemplate. For any header you
- SeparatorTemplate. For separating
items (usually in the form of <br>, <hr> etc.).
- FooterTemplate. For footers!
Before I show you the code there is one thing
that I should tell you about.
DataBind() is a method that takes all of the
data on the page and binds it to the controls that you have specified for
The first line sets the datasource and the
second binds the data to the repeater, without binding, the data wouldn't be
Remember that this code just snaps on to the
one in the introduction.
<asp:repeater id="Rpt" runat="server">
<table border="0" cellspacing="1" cellpadding="3">
<td bgcolor="#6699FF" width="25%">Last Name</td>
<td bgcolor="#6699FF" width="25%">First Name</td>
<%# Container.DataItem("LName") %>
<%# Container.DataItem("FName") %>
Lets look at this in sections -
- We first set the repeater's datasource,
which is the datatable "users". DefaultView is the view of the table, we'll
look at views later (in another Part).
- Then we bind the data to the repeater.
- We start the repeater in the normal way to
start any Web Form Control.
- The HeaderTemplate starts a table
with 2 columns, First Name and Last Name.
- The ItemTemplate fills each column
with the appropriate data, 'Container refers to the DataSource, we'll talk
about that later (in another Part).
- Finally the FooterTemplate closes the
table and we then close up the remaining open tags.
I haven't put in any kind of Alternating Item
in here, but its simple enough.
That is all a Repeater can do, it presents data
and that is all there is to it.