The primary function of the Repeater control is to control data in a more free way and present data in a non-table form. The most important part of the Repeater control is the template, which allows you to define five templates;
1. itemtemplate: a data template, which is required by the Repeater control.
2. alternatingitemtemplate: an optional parameter.
3. separatortemplate, which is an optional parameter.
4. headertemplate: Header template. An optional parameter.
5. footertemplate: End template. Optional.
<Asp: repeater id = "Rep" runat = "server">
<Itemtemplate>
<B>
<% # Databinder. eval (container. dataitem, "name") %>
(<% # Databinder. eval (container. dataitem, "student ID") %>) </B>
Mathematical score: <% # databinder. eval (container. dataitem, "Mathematics") %> <br>
</Itemtemplate>
</ASP: repeater>
Protected void page_load (Object sender, eventargs E)
{
String provider, database, connstr, SQL;
Provider = "Microsoft. Jet. oledb.4.0 ;";
Database = server. mappath ("person. mdb ");
Connstr = "provider =" + provider + "Data Source =" + database;
SQL = "select * from Grade ";
Oledbdataadapter da;
DA = new oledbdataadapter (SQL, connstr );
Dataset DS = new dataset ();
Da. Fill (DS, "Grade ");
Rep. datasource = Ds. Tables ["Grade"]. defaultview;
Rep. databind ();
}
You can also use other templates. <Asp: repeater id = "Rep" runat = "server">
<Headertemplate>
First graduates renewal table <p>
</Headertemplate>
<Itemtemplate>
<B>
<% # Databinder. eval (container. dataitem, "name") %>
(<% # Databinder. eval (container. dataitem, "student ID") %>) </B> mathematical score: <% # databinder. eval (container. dataitem, "Mathematics") %> <br>
</Itemtemplate>
<Alternatingitemtemplate>
<Font color = "blue"> <B>
<% # Databinder. eval (container. dataitem, "name") %>
(<% # Databinder. eval (container. dataitem, "student ID") %>) </B> mathematical score: <% # databinder. eval (container. dataitem, "Mathematics") %> <br>
</Font>
</Alternatingitemtemplate>
<Separatortemplate>
<HR width = "80%" align = "Left"/>
</Separatortemplate>
<Footertemplate>
<P>
End now! </Footertemplate>
</ASP: repeater>
Protected void page_load (Object sender, eventargs E)
{
String provider, database, connstr, SQL;
Provider = "Microsoft. Jet. oledb.4.0 ;";
Database = server. mappath ("person. mdb ");
Connstr = "provider =" + provider + "Data Source =" + database;
SQL = "select * from Grade ";
Oledbdataadapter da;
DA = new oledbdataadapter (SQL, connstr );
Dataset DS = new dataset ();
Da. Fill (DS, "Grade ");
Rep. datasource = Ds. Tables ["Grade"]. defaultview;
Rep. databind ();
}