Use of the databind and repeater controls.

Source: Internet
Author: User

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.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.