asp.net repeater use Aspnetpager Paging control _ Practical Tips

Source: Internet
Author: User
One, Aspnetpager paging control
Pagination is one of the most commonly used features in Web applications, and in ASP.net, although it has a DataGrid (ASP.net 1.1) and a GridView (ASP.net 2.0) control that can be paginated, its paging functionality is unsatisfactory, such as poor customization, Paging is not possible through URLs, and sometimes we need to page DataList and repeater even custom data-bound controls, and manual paging code is not only technically difficult, cumbersome, and very low code reuse rate, So paging has become one of the most vexing problems for many asp.net programmers.
Aspnetpager for ASP.net paging controls, proposed a unique solution to the problem of paging in the ASP.net, the paging function and the data display function completely independent, by the user control data acquisition and display mode, so can be flexibly applied to any need to implement the paging function of the place, For data-bound controls such as GridView, DataList, and Repeater, to implement paging, render custom paging data, and to make picture browsing programs, and so on, because the Aspnetpager control and data are separate, so that the data to be paginated can come from any data source, such as SQL Servers, Oracle, Access, MySQL, DB2 databases, and XML files, memory data, or data in the cache, file systems, and so on.
second, the basic attributes:
Alwaysshow:
By default, when the data to be paginated is only one page, Aspnetpager defaults to Automatic crisis and does not display any visible content on the page, setting this property to true even if the total number of pages is only one page, Aspnetpager will also display the pager element.
Firstpagetext:
Gets or sets the text displayed for the first-page button.
Lastpagetext:
Gets or sets the text displayed for the last-page button.
NextPageText:
Gets or sets the text to display for the next-page button.
Prevpagetext:
Gets or sets the text displayed for the previous-page button.
PageSize:
Gets or sets the number of items to display per page. (This value Gets or sets the number of entries for the data rendering control to display data in a datasheet each time, based on that value and RecordCount, aspnetpager the total page size required to display all the data, that is, the PageCount value.) )
CssClass:
CSS class name applied to the control
Currentpagebuttonclass:
Gets or sets the cascading style sheet (CSS) class for the current pager button of the Aspnetpager page control.
Pageindexboxtype:
or set the display type of the page index box, which is a text box that allows the user to enter it manually 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 paginated reaches that value, the page index input text box is automatically displayed, with the default value of 30. This option has no effect when Showpageindexbox is set to never or always.
third, style style:
===== NetEase Style =====
Anpager. CPB {background: #1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC; color: #FFFFFF; font-weight:bold;margin : 5px 4px 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:4p x 5px 0;text-decoration:none}
. Anpager A:hover{background: #1F3A87 None repeat scroll 0 0;border:1px solid #1F3A87; color: #FFFFFF;}
property setting: Cssclass= "Anpager" currentpagebuttonclass= "CPB"
===== Pat NET 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. CPB {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 setting: Cssclass= "Paginator" currentpagebuttonclass= "CPB"
===== Thunderbolt Style =====
. pages {color: #999;}
. pages a,. 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. CPB {font-weight:bold; color: #fff; background: #E61636; border:1px solid #E61636;}
Property settings: cssclass= "pages" currentpagebuttonclass= "CPB"
four, how to call:
index.aspx file
Copy Code code 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 ">
<title></title>
<link href= "Inc/css.css" rel= "stylesheet" type= "Text/css"/>
<style type= "Text/css" >
* * NetEase Style * *
Anpager. CPB {background: #1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC; color: #FFFFFF; font-weight:bold;margin : 5px 4px 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:4p x 5px 0;text-decoration:none}
. Anpager A:hover{background: #1F3A87 None repeat scroll 0 0;border:1px solid #1F3A87; color: #FFFFFF;}
* * PAT NET 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. CPB {padding:1px 6px;font-weight:bold; Font-size:13px;border:none}
. paginator a:hover {color: #fff; background: #ffa501; Border-color: #ffa501; text-decoration:none;}
* * Thunderbolt Style * *
. pages {color: #999}
. pages a,. 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. CPB {font-weight:bold; color: #fff; background: #E61636; border:1px solid #E61636;}
. Code{font-weight:bold;color:blue}
</style>
<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= "Home" lastpagetext= "last" nextpagetext= "Next" prevpagetext= "prev"
showmorebuttons= "False" showpageindexbox= "Never" >
</webdiyer:AspNetPager></div>
</div>
</form>
</body>

Index.aspx.cs
Copy Code code 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 sentence 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.