Code
// 1. Use the Repeater control to display data (specified field display)
Repeaterbind. datasource = DS. Tables [ " Testtable " ];
Repeaterbind. databind ();
< ASP: repeater ID = " Repeaterbind " Runat = " Server " >
< Itemtemplate >
< Li >
<% # Databinder. eval (container. dataitem, " Titleofcourtesy " ) %>
<% # Databinder. eval (container. dataitem, " Lastname " ) %>
<% # Databinder. eval (container. dataitem, " Firstname " ) %>
</ Li >
</ Itemtemplate >
</ ASP: Repeater >
-------------------------------------------------
// 2 repeater controls alternate item display
< ASP: repeater ID = " Repeaterbind " Runat = " Server " >
< Headertemplate >
< H3 > Header </ H3 >
</ Headertemplate >
< Itemtemplate >
< Li >
<% # Databinder. eval (container. dataitem, " Lastname " ) %> Alternate items
</ Li >
</ Itemtemplate >
< Alternatingitemtemplate >
< H4 > < Font color = Red >
<% # Databinder. eval (container. dataitem, " Lastname " ) %> Alternate items
</ Font >
</ H4 >
</ Alternatingitemtemplate >
< Footertemplate >
< H3 > </ H3 > Foot
</ Footertemplate >
</ ASP: Repeater >
// 3. Use of the paging class and Repeater control Paging
Private Void Page_load ( Object Sender, system. eventargs E)
{
// Data Binding during initial Page Testing
If ( ! Ispostback)
Repeaterdatabind ();
}
Private Void Repeaterdatabind ()
{
// Define the data connection object. The database connection string is defined in the web. config file.
Sqlconnection Conn = New Sqlconnection (configurationsettings. receivettings [ " Connectionsqlserver " ]. Tostring ());
// Create a data adapter object
Sqldataadapter da = New Sqldataadapter ( " Select lastname, firstname, titleofcourtesy from employees " , Conn );
// Create a DataSet object
Dataset DS = New Dataset ();
Try
{
// Fill a dataset
Da. Fill (DS, " Testtable " );
// Create a paging class
Pageddatasource objpage = New Pageddatasource ();
// Set Data Source
Objpage. datasource = DS. Tables [ " Testtable " ]. Defaultview;
// Pagination allowed
Objpage. allowpaging = True ;
// Set the number of items displayed on each page
Objpage. pagesize = 5 ;
// Define variables to save the index of the current page
Int Curpage;
// Determine whether a page Jump request exists
If (Request. querystring [ " Page " ] ! = Null )
Curpage = Convert. toint32 (request. querystring [ " Page " ]);
Else
Curpage = 1 ;
// Set the index of the current page
Objpage. currentpageindex = Curpage - 1 ;
// Show status information
Lblcurpage. Text = " Current page: Section " + Curpage. tostring () + " Page " ;
// If the current page is not the homepage
If ( ! Objpage. isfirstpage)
// Define the URL of the hyperlink "Previous Page" as the virtual path of the current execution page, and pass the index value on the next page.
Lnkprev. navigateurl = Request. currentexecutionfilepath + " ? Page = " + Convert. tostring (curpage - 1 );
// If the current page is not the last page
If ( ! Objpage. islastpage)
// The URL of the "next page" hyperlink is defined as the virtual path of the current execution page, and the index value on the next page is passed.
Lnknext. navigateurl = Request. currentexecutionfilepath + " ? Page = " + Convert. tostring (curpage + 1 );
// bind data
repeaterpage. datasource = objpage;
repeaterpage. databind ();
}< br> catch (Exception error)
{< br> response. write (error. tostring ();
}< BR >}< br>