The Repeater control is used for loop output.
Introduction:
<Itemtemplate> normal project display template 1 3 5 7 rows display </itemtemplate>
<Alternatingitemtemplate> staggered display template 2 4 6 8 rows </alternatingitemtemplate>
<Separatortemplate> delimiter template for each line </separatortemplate>
<Headertemplate> header
<Footertemplate> footer </footertemplate>
Use of iner in Data Binding
<% # (Datarowview) container. dataitem) ["num"] %> or
<% # Databinder. eval (container. dataitem, "num", "{0}") %> the effect is the same as that in ASP <% = RS ("num")>
Retrieve the num column from the container
<% # Databinder. eval (container. dataitem, "num", "{0: c}") % >{} indicates that both the data to be generated C indicates that the RMB symbol is entered.
For example:
Database Object Creation
Con. open ();
Sqldataadapter sad = new sqldataadapter (); // create a data adapter object
Sad. selectcommand = new sqlcommand ("select * From person", con); // instantiate
Dataset DS = new dataset (); // defines a dataset.
Sad. Fill (DS, "info"); // use the data adapter to fill the dataset with the info table
This. repeater1.datasource = Ds. Tables ["info"]; // you can specify a data source.
This. repeater1.databind (); // bind
<Asp: repeater id = "repeater1" runat = "server">
<Itemtemplate>
<% # Databinder. eval (container. dataitem, "pname", "Name: {0}") %>
<% # Databinder. eval (container. dataitem, "iner X") %>
</Itemtemplate>
<Alternatingitemtemplate>
<Font color = blue>
<% # Databinder. eval (container. dataitem, "pname", "Name: {0}") %>
<% # Databinder. eval (container. dataitem, "iner X") %> </font>
</Alternatingitemtemplate>
<Headertemplate> Header
</Headertemplate>
<Footertemplate> footer
</Footertemplate>
<Separatortemplate>
<HR color = blue size = 1/>
</Separatortemplate>
</ASP: repeater>
Paging design:
Int curpage = 1;
Pageddatasource PS = new pageddatasource ();
PS. datasource = Ds. Tables ["info"]. defaultview;
PS. allowpaging = true;
PS. pagesize = 4;
PS. currentpageindex = curpage-1;
This. repeater1.datasource = Ps; // you can specify the data source.
This. repeater1.databind (); // bind
You can change the value of "curpage" each time you click.
You can add one to the next curpage.
Implementation shown in the table:
1. Add <Table> </table> to the header and footer respectively.
<Headertemplate> <Table>
<Footertemplate> </table> </footertemplate>
2. Go to </itemtemplate> <tr> <TD> <% # %> </TD> <tr> <alternatingitemtemplate>
In this way, the table is added.