Use the AspNetPager paging Control for Repeater in asp.net

Source: Internet
Author: User

I. AspNetPager Page Control
Paging is one of the most commonly used functions in Web applications. NET, although it comes with a paging DataGrid (asp.net 1.1) and GridView (asp.net 2.0) controls, its paging function is not satisfactory, for example, poor customization and paging functions cannot be implemented through URLs. Sometimes we need to pagination DataList, Repeater, and even custom data binding controls, manual paging code writing is not only technically difficult, tedious, and extremely low code reuse rate, so paging has become a lot of ASP. one of the biggest headaches for NET programmers.
AspNetPager for ASP. the limitations of the NET paging control, and proposed a different solution to the paging problem in asp.net, that is, the paging navigation function and the data display function are completely independent, users can control the data acquisition and display methods by themselves, so they can be flexibly applied to any areas where the paging navigation function is required, for example, you can bind controls such as GridView, DataList, and Repeater to implement paging, display custom paging data, and create Image Browsing programs. Because the AspNetPager control and data are independent, therefore, the data to be paged can come from any data source, such as SQL Server, Oracle, Access, mysql, DB2, and other databases as well as XML files, memory data, or cached data and file systems.
Ii. basic attributes:
AlwaysShow:
By default, if only one page of data is displayed on the page, AspNetPager automatically reports a dangerous period instead of any visible content on the page. If this attribute value is set to true, even if the total number of pages is only one page, AspNetPager displays the paging navigation element.
FirstPageText:
Obtain or set the text displayed on the first page.
LastPageText:
Obtain or set the text displayed on the last page.
NextPageText:
Obtain or set the text displayed on the next page.
PrevPageText:
Obtain or set the text displayed on the previous page.
PageSize:
Obtain or set the number of items displayed on each page. (This value gets or sets the number of data items in the data presentation control each time to display the data items in the data table. AspNetPager calculates the total number of pages required to display all data based on this value and RecordCount, that is, the PageCount value. )
CssClass:
Css class name applied to the control
CurrentPageButtonClass:
Gets or sets the Cascading Style Sheet (CSS) class of the current page navigation button of the AspNetPager page control.
PageIndexBoxType:
Alternatively, you can set the display type of the index box, which can be a text box that you can manually enter and a drop-down box that can only be selected.
ShowBoxThreshold:
When ShowPageIndexBox is set to Auto (default) and the total number of pages of data to be paged reaches this value, the page index input text box is displayed automatically. The default value is 30. This option does not work when ShowPageIndexBox is set to Never or Always.
Iii. style:
===== Netease style =====
. Anpager. ECC {background: #1F3A87 none repeat scroll 0 0; border: 1px solid # CCCCCC; color: # FFFFFF; font-weight: bold; margin: 5px 4px 0 0 0; padding: 4px 5px 0 ;}
. Anpager a {background: # FFFFFF none repeat scroll 0 0; border: 1px solid # CCCCCC; color: #1F3A87; margin: 5px 4px 0 0; padding: 4px 5px 0; text-decoration: none}
. Anpager a: hover {background: #1F3A87 none repeat scroll 0 0; border: 1px solid #1F3A87; color: # FFFFFF ;}
Property settings: CssClass = "anpager" CurrentPageButtonClass = "cardiopulmonary bypass"
===== Pat network style ====
. Paginator {font: 11px Arial, Helvetica, sans-serif; padding: 10px 20px 10px 0; margin: 0px ;}
. Paginator a {padding: 1px 6px; border: solid 1px # ddd; background: # fff; text-decoration: none; margin-right: 2px}
. Paginator a: visited {padding: 1px 6px; border: solid 1px # ddd; background: # fff; text-decoration: none ;}
. Paginator. ECC {padding: 1px 6px; font-weight: bold; font-size: 13px; border: none}
. Paginator a: hover {color: # fff; background: # ffa501; border-color: # ffa501; text-decoration: none ;}
Property settings: CssClass = "paginator" CurrentPageButtonClass = "cardiopulmonary bypass"
===== Thunder style ====
. Pages {color: #999 ;}
. Pages ,. pages. cpb {text-decoration: none; float: left; padding: 0 5px; border: 1px solid # ddd; background: # ffff; margin: 0 2px; font-size: 11px; color: #000 ;}
. Pages a: hover {background-color: # E61636; color: # fff; border: 1px solid # E61636; text-decoration: none ;}
. Pages. ECC {font-weight: bold; color: # fff; background: # E61636; border: 1px solid # E61636 ;}
Property settings: CssClass = "pages" CurrentPageButtonClass = "cardiopulmonary bypass"
4. How to call:
Index. aspx File
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default2.aspx. cs" Inherits = "Default2" %>
<% @ Register Assembly = "AspNetPager" Namespace = "Wuqi. Webdiyer" TagPrefix = "webdiyer" %>
<% @ Register src = "hand. ascx" tagname = "hand" tagprefix = "uc1" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Link href = "inc/css.css" rel = "stylesheet" type = "text/css"/>
<Style type = "text/css">
/* Netease style */
. Anpager. ECC {background: #1F3A87 none repeat scroll 0 0; border: 1px solid # CCCCCC; color: # FFFFFF; font-weight: bold; margin: 5px 4px 0 0 0; padding: 4px 5px 0 ;}
. Anpager a {background: # FFFFFF none repeat scroll 0 0; border: 1px solid # CCCCCC; color: #1F3A87; margin: 5px 4px 0 0; padding: 4px 5px 0; text-decoration: none}
. Anpager a: hover {background: #1F3A87 none repeat scroll 0 0; border: 1px solid #1F3A87; color: # FFFFFF ;}
/* Pat network style */
. Paginator {font: 11px Arial, Helvetica, sans-serif; padding: 10px 20px 10px 0; margin: 0px ;}
. Paginator a {padding: 1px 6px; border: solid 1px # ddd; background: # fff; text-decoration: none; margin-right: 2px}
. Paginator a: visited {padding: 1px 6px; border: solid 1px # ddd; background: # fff; text-decoration: none ;}
. Paginator. ECC {padding: 1px 6px; font-weight: bold; font-size: 13px; border: none}
. Paginator a: hover {color: # fff; background: # ffa501; border-color: # ffa501; text-decoration: none ;}
/* Thunder style */
. Pages {color: #999}
. Pages ,. pages. cpb {text-decoration: none; float: left; padding: 0 5px; border: 1px solid # ddd; background: # ffff; margin: 0 2px; font-size: 11px; color: #000 ;}
. Pages a: hover {background-color: # E61636; color: # fff; border: 1px solid # E61636; text-decoration: none ;}
. Pages. ECC {font-weight: bold; color: # fff; background: # E61636; border: 1px solid # E61636 ;}
. Code {font-weight: bold; color: blue}
</Style>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Uc1: hand ID = "hand1" runat = "server"/>
<Div style = "text-align: left; line-height: 20px">
<Asp: Repeater ID = "SoftDown" runat = "server">
<ItemTemplate>
<Div style = "border-bottom: 1px solid #000000"> <% # Eval ("E_id") %> <% # Eval ("Class ") %> <br> <% # Eval ("DownTitle") %> <br> <% # Eval ("PageHome") %> </div>
</ItemTemplate>
</Asp: Repeater>
<Div style = "text-align: right; padding-top: 10px">
<Webdiyer: AspNetPager ID = "AspNetPager1" runat = "server" pagesize = "5" CssClass = "anpager" onpagechanged = "AspNetPager1_PageChanged"
FirstPageText = "Homepage" LastPageText = "last page" NextPageText = "next page" PrevPageText = "Previous Page"
ShowMoreButtons = "False" ShowPageIndexBox = "Never">
</Webdiyer: AspNetPager> </div>
</Div>
</Form>
</Body>
</Html>

Index. aspx. cs
Copy codeThe Code is as follows:
Using System;
Using System. Collections;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Data. SqlClient;
Using GHSqlConn;
Using Wuqi. Webdiyer;
Public partial class Default2: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack ){
SqlConnection conn = DB. getConnection ();
Conn. Open ();
SqlCommand Count = new SqlCommand ();
Count. Connection = conn;
Count. CommandText = "select count (*) from T_SoftDown1 ";
AspNetPager1.RecordCount = (int) Count. ExecuteScalar ();
// Response. Write (AspNetPager1.RecordCount );
Conn. Close ();
BindData ();
}
}
Public void BindData ()
{
SqlConnection conn = DB. getConnection ();
String SQL = "select * from T_SoftDown1 order by E_id desc"; // This statement should be used in large data: select top query statement
SqlDataAdapter da = new SqlDataAdapter (SQL, conn );
DataSet ds = new DataSet ();
Da. Fill (ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex-1), AspNetPager1.PageSize, "temptbl ");
DataTable dt = ds. Tables ["temptbl"];
SoftDown. DataSource = dt;
SoftDown. DataBind ();
}
Protected void AspNetPager1_PageChanged (object src, EventArgs e)
{
// AspNetPager1.CurrentPageIndex = e. NewPageIndex;
BindData ();
}
}

Related Article

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.