asp.net and Repeater use the AspNetPager paging control

  • 2020-05-09 18:28:24
  • OfStack

1. AspNetPager paging control
Paging is Web application to one of the most commonly used function of 1, in ASP. NET, although can comes with a paging DataGrid (asp. net 1.1) and GridView (asp. net 2.0) controls, but its paging function is not very desirable, such as poor customizability, cannot be achieved through Url paging, etc., and sometimes we need to DataList and Repeater even custom data binding controls paging, Writing paging code by hand is not only technically difficult and tedious, but also has a very low rate of code reuse. As a result, paging has become one of the biggest headaches for many programmers of ASP.NET.
AspNetPager against ASP. NET paging controls, puts forward a different solution asp. net paging in the problem, the page navigation and data display functions completely separated, controlled by the user's own data acquisition and display mode, so it can be flexibly applied to any areas that need to implement page navigation function such as GridView, DataList and Repeater data-bound controls implement paging, render custom data paging, and made the image browsing, etc., Because the AspNetPager control and data are independent, the data to be paged can come from any data source, such as databases such as SQL Server, Oracle, Access, mysql, DB2, as well as XML files, in-memory data or data in cache, file systems, and so on.
2. Basic properties:
AlwaysShow:
By default, when there is only 1 page of data to be paged, AspNetPager will automatically risk not displaying any visible content on the page by default, and AspNetPager will display the paged navigation element even if the total number of pages is only 1 page when this attribute value is set to true.
FirstPageText:
Gets or sets the text that the page 1 button displays.
LastPageText:
Gets or sets the text displayed by the button on the last page.
NextPageText:
Gets or sets the text to be displayed by the button on the next page.
PrevPageText:
Gets or sets the text displayed by the button on the previous page.
PageSize:
Gets or sets the number of items displayed per page. (this value gets or sets the number of items in the data table that the data rendering control wants to display at a time. AspNetPager calculates the total number of pages needed to display all the data based on this value and RecordCount, which is the value of PageCount. )
CssClass:
The 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 paging control.
PageIndexBoxType:
Or set the display type of the page index box, which can be a text box that allows the user to manually enter and a drop-down box that can only be selected.
ShowBoxThreshold:
When ShowPageIndexBox is set to Auto (the default) and the total number of pages of data to be paged reaches this value, the page index is automatically displayed in the text box. The default value is 30. This option has no effect when ShowPageIndexBox is set to Never or Always.
3. Style and 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: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="cpb"
===== paipai 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 Settings: 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"
4. How to call:
index aspx file
 
<%@ 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 .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:4px 5px 0;text-decoration:none} 
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;} 
/* Paipai 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> 
</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=" Home page " LastPageText=" back " NextPageText=" Under the 1 page " PrevPageText=" on 1 page " 
ShowMoreButtons="False" ShowPageIndexBox="Never"> 
</webdiyer:AspNetPager></div> 
</div> 
</form> 
</body> 
</html> 

index.aspx.cs
 
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 sets: select top The query  
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 articles: